8d5c197f99
* Loosen check in getIndexTypeForMappedType to directly map property names when any indexy type is present * Handle homomorphic mappings better in keyof, add specific relationship rule for relating generic keyof MappedType to handle remapped keys * Remove trailing whitespace
44 lines
1.8 KiB
Plaintext
44 lines
1.8 KiB
Plaintext
=== tests/cases/compiler/computedTypesKeyofNoIndexSignatureType.ts ===
|
|
type Compute<A> = { [K in keyof A]: Compute<A[K]>; } & {};
|
|
>Compute : { [K in keyof A]: { [K in keyof A[K]]: { [K in keyof A[K][K]]: { [K in keyof A[K][K][K]]: { [K in keyof A[K][K][K][K]]: { [K in keyof A[K][K][K][K][K]]: { [K in keyof A[K][K][K][K][K][K]]: { [K in keyof A[K][K][K][K][K][K][K]]: { [K in keyof A[K][K][K][K][K][K][K][K]]: { [K in keyof A[K][K][K][K][K][K][K][K][K]]: { [K in keyof A[K][K][K][K][K][K][K][K][K][K]]: any; }; }; }; }; }; }; }; }; }; }; }
|
|
|
|
type EqualsTest<T> = <A>() => A extends T ? 1 : 0;
|
|
>EqualsTest : EqualsTest<T>
|
|
|
|
type Equals<A1, A2> = EqualsTest<A2> extends EqualsTest<A1> ? 1 : 0;
|
|
>Equals : Equals<A1, A2>
|
|
|
|
type Filter<K, I> = Equals<K, I> extends 1 ? never : K;
|
|
>Filter : Filter<K, I>
|
|
|
|
type OmitIndex<T, I extends string | number> = {
|
|
>OmitIndex : OmitIndex<T, I>
|
|
|
|
[K in keyof T as Filter<K, I>]: T[K];
|
|
};
|
|
|
|
type IndexObject = { [key: string]: unknown; };
|
|
>IndexObject : IndexObject
|
|
>key : string
|
|
|
|
type FooBar = { foo: "hello"; bar: "world"; };
|
|
>FooBar : FooBar
|
|
>foo : "hello"
|
|
>bar : "world"
|
|
|
|
type WithIndex = Compute<FooBar & IndexObject>; // { [x: string]: {}; foo: "hello"; bar: "world"; } <-- OK
|
|
>WithIndex : { [x: string]: {}; foo: "hello"; bar: "world"; }
|
|
|
|
type WithoutIndex = OmitIndex<WithIndex, string>; // { foo: "hello"; bar: "world"; } <-- OK
|
|
>WithoutIndex : OmitIndex<{ [x: string]: {}; foo: "hello"; bar: "world"; }, string>
|
|
|
|
type FooBarKey = keyof FooBar; // "foo" | "bar" <-- OK
|
|
>FooBarKey : keyof FooBar
|
|
|
|
type WithIndexKey = keyof WithIndex; // string | number <-- Expected: string
|
|
>WithIndexKey : string | number
|
|
|
|
type WithoutIndexKey = keyof WithoutIndex; // number <-- Expected: "foo" | "bar"
|
|
>WithoutIndexKey : "foo" | "bar"
|
|
|