Type Challenges Judge

Chainable Options

提出詳細

type Chainable<T = {}> = { option<Key extends string, Value>( key: Key extends keyof T ? never : Key, value: Value ): Chainable<T & { [K in Key]: Value }> get(): T }
提出日時2023-08-10 02:05:38
問題Chainable Options
ユーザーtekihei2317
ステータスAccepted
テストケース
import type { Alike, Expect } from '@type-challenges/utils' declare const a: Chainable const result1 = a .option('foo', 123) .option('bar', { value: 'Hello World' }) .option('name', 'type-challenges') .get() const result2 = a .option('name', 'another name') // @ts-expect-error .option('name', 'last name') .get() type cases = [ Expect<Alike<typeof result1, Expected1>>, Expect<Alike<typeof result2, Expected2>>, ] type Expected1 = { foo: number bar: { value: string } name: string } type Expected2 = { name: string }