Type Challenges Judge

Chainable Options

提出詳細

type Without<T, K> = K extends keyof T ? never : K type Chainable<C extends { [k: number | string]: unknown } = {}> = { option<K extends string, V>(key: Without<C, K>, value: V): K extends keyof C ? Chainable<Omit<C, K> & { [P in K]: V }> : Chainable<C & { [P in K]: V }> get(): C }
提出日時2023-08-08 15:56:08
問題Chainable Options
ユーザーookkoouu
ステータス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 }