Remove Index Signature
提出詳細
type Includes<T, U> = U extends T ? true : false; // string, number, symbolのいずれかであるか type IsIndexType<T> = [Includes<T, string>, Includes<T, number>, Includes<T, symbol>][number] extends false ? false : true; type RemoveIndexSignature<T> = { [K in keyof T as IsIndexType<K> extends true ? never : K]: T[K] }
提出日時 | 2023-08-12 08:48:04 |
---|---|
問題 | Remove Index Signature |
ユーザー | tekihei2317 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type Foo = { [key: string]: any foo(): void } type Bar = { [key: number]: any bar(): void } type FooBar = { [key: symbol]: any foobar(): void } type Baz = { bar(): void baz: string } type cases = [ Expect<Equal<RemoveIndexSignature<Foo>, { foo(): void }>>, Expect<Equal<RemoveIndexSignature<Bar>, { bar(): void }>>, Expect<Equal<RemoveIndexSignature<FooBar>, { foobar(): void }>>, Expect<Equal<RemoveIndexSignature<Baz>, { bar(): void; baz: string }>>, ]