mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Merge pull request #31002 from Microsoft/fixIsStringIndexSignatureOnlyType
Fix isStringIndexSignatureOnlyType function
This commit is contained in:
@@ -12049,7 +12049,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isStringIndexSignatureOnlyType(type: Type): boolean {
|
||||
return type.flags & TypeFlags.Object && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) ||
|
||||
return type.flags & TypeFlags.Object && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) ||
|
||||
type.flags & TypeFlags.UnionOrIntersection && every((<UnionOrIntersectionType>type).types, isStringIndexSignatureOnlyType) ||
|
||||
false;
|
||||
}
|
||||
|
||||
@@ -187,4 +187,11 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23
|
||||
!!! error TS2322: Type '123' is not assignable to type '123 & "some string"'.
|
||||
!!! error TS2322: Type '123' is not assignable to type '"some string"'.
|
||||
}
|
||||
|
||||
// Repro from #30920
|
||||
|
||||
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
|
||||
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
|
||||
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
|
||||
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
|
||||
|
||||
@@ -108,6 +108,13 @@ interface Type {
|
||||
function get123<K extends keyof Type>(): Type[K] {
|
||||
return 123; // Error
|
||||
}
|
||||
|
||||
// Repro from #30920
|
||||
|
||||
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
|
||||
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
|
||||
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
|
||||
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
|
||||
|
||||
|
||||
//// [keyofAndIndexedAccess2.js]
|
||||
|
||||
@@ -388,3 +388,49 @@ function get123<K extends keyof Type>(): Type[K] {
|
||||
return 123; // Error
|
||||
}
|
||||
|
||||
// Repro from #30920
|
||||
|
||||
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
|
||||
>StrictExtract : Symbol(StrictExtract, Decl(keyofAndIndexedAccess2.ts, 108, 1))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 112, 19))
|
||||
>U : Symbol(U, Decl(keyofAndIndexedAccess2.ts, 112, 21))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 112, 19))
|
||||
>U : Symbol(U, Decl(keyofAndIndexedAccess2.ts, 112, 21))
|
||||
>U : Symbol(U, Decl(keyofAndIndexedAccess2.ts, 112, 21))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 112, 19))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 112, 19))
|
||||
|
||||
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
|
||||
>StrictExclude : Symbol(StrictExclude, Decl(keyofAndIndexedAccess2.ts, 112, 73))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 113, 19))
|
||||
>U : Symbol(U, Decl(keyofAndIndexedAccess2.ts, 113, 21))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 113, 19))
|
||||
>StrictExtract : Symbol(StrictExtract, Decl(keyofAndIndexedAccess2.ts, 108, 1))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 113, 19))
|
||||
>U : Symbol(U, Decl(keyofAndIndexedAccess2.ts, 113, 21))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 113, 19))
|
||||
|
||||
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
|
||||
>A : Symbol(A, Decl(keyofAndIndexedAccess2.ts, 113, 69))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 114, 7))
|
||||
>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 114, 15))
|
||||
>P : Symbol(P, Decl(keyofAndIndexedAccess2.ts, 114, 23))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 114, 7))
|
||||
>P : Symbol(P, Decl(keyofAndIndexedAccess2.ts, 114, 23))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 114, 7))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 114, 7))
|
||||
>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 114, 15))
|
||||
|
||||
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
|
||||
>B : Symbol(B, Decl(keyofAndIndexedAccess2.ts, 114, 62))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 115, 7))
|
||||
>V : Symbol(V, Decl(keyofAndIndexedAccess2.ts, 115, 9))
|
||||
>A : Symbol(A, Decl(keyofAndIndexedAccess2.ts, 113, 69))
|
||||
>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 115, 20))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 115, 7))
|
||||
>StrictExclude : Symbol(StrictExclude, Decl(keyofAndIndexedAccess2.ts, 112, 73))
|
||||
>B : Symbol(B, Decl(keyofAndIndexedAccess2.ts, 114, 62))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 115, 7))
|
||||
>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 115, 20))
|
||||
>V : Symbol(V, Decl(keyofAndIndexedAccess2.ts, 115, 9))
|
||||
|
||||
|
||||
@@ -423,3 +423,17 @@ function get123<K extends keyof Type>(): Type[K] {
|
||||
>123 : 123
|
||||
}
|
||||
|
||||
// Repro from #30920
|
||||
|
||||
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
|
||||
>StrictExtract : StrictExtract<T, U>
|
||||
|
||||
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
|
||||
>StrictExclude : StrictExclude<T, U>
|
||||
|
||||
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
|
||||
>A : A<T>
|
||||
|
||||
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
|
||||
>B : A<{ [Q in keyof T]: StrictExclude<A<{ [Q in keyof T[Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q][Q][Q][Q][Q]]: StrictExclude<A<{ [Q in keyof T[Q][Q][Q][Q][Q][Q][Q][Q][Q][Q]]: StrictExclude<A<any>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>
|
||||
|
||||
|
||||
@@ -110,3 +110,10 @@ interface Type {
|
||||
function get123<K extends keyof Type>(): Type[K] {
|
||||
return 123; // Error
|
||||
}
|
||||
|
||||
// Repro from #30920
|
||||
|
||||
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
|
||||
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
|
||||
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
|
||||
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
|
||||
|
||||
Reference in New Issue
Block a user