mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Merge pull request #23966 from Microsoft/fixIndexedAccessAnyConstraint
Fix indexed access with 'any' constraint
This commit is contained in:
commit
40e0ab72d2
@ -10755,7 +10755,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
const constraint = getConstraintForRelation(<TypeParameter>source);
|
||||
if (!constraint || constraint.flags & TypeFlags.Any) {
|
||||
if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
|
||||
// A type variable with no constraint is not related to the non-primitive object type.
|
||||
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
|
||||
errorInfo = saveErrorInfo;
|
||||
|
||||
@ -627,6 +627,14 @@ class Unbounded<T> {
|
||||
let y: {} | undefined | null = x;
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #23940
|
||||
|
||||
interface I7 {
|
||||
x: any;
|
||||
}
|
||||
type Foo7<T extends number> = T;
|
||||
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
|
||||
|
||||
|
||||
//// [keyofAndIndexedAccess.js]
|
||||
@ -1368,3 +1376,8 @@ declare function fn<T extends I, K extends keyof T>(o: T, k: K): void;
|
||||
declare class Unbounded<T> {
|
||||
foo(x: T[keyof T]): void;
|
||||
}
|
||||
interface I7 {
|
||||
x: any;
|
||||
}
|
||||
declare type Foo7<T extends number> = T;
|
||||
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
|
||||
|
||||
@ -2235,3 +2235,26 @@ class Unbounded<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #23940
|
||||
|
||||
interface I7 {
|
||||
>I7 : Symbol(I7, Decl(keyofAndIndexedAccess.ts, 627, 1))
|
||||
|
||||
x: any;
|
||||
>x : Symbol(I7.x, Decl(keyofAndIndexedAccess.ts, 631, 14))
|
||||
}
|
||||
type Foo7<T extends number> = T;
|
||||
>Foo7 : Symbol(Foo7, Decl(keyofAndIndexedAccess.ts, 633, 1))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 634, 10))
|
||||
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 634, 10))
|
||||
|
||||
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
|
||||
>f7 : Symbol(f7, Decl(keyofAndIndexedAccess.ts, 634, 32))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 635, 20))
|
||||
>I7 : Symbol(I7, Decl(keyofAndIndexedAccess.ts, 627, 1))
|
||||
>type : Symbol(type, Decl(keyofAndIndexedAccess.ts, 635, 40))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 635, 20))
|
||||
>Foo7 : Symbol(Foo7, Decl(keyofAndIndexedAccess.ts, 633, 1))
|
||||
>I7 : Symbol(I7, Decl(keyofAndIndexedAccess.ts, 627, 1))
|
||||
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 635, 20))
|
||||
|
||||
|
||||
@ -2591,3 +2591,26 @@ class Unbounded<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #23940
|
||||
|
||||
interface I7 {
|
||||
>I7 : I7
|
||||
|
||||
x: any;
|
||||
>x : any
|
||||
}
|
||||
type Foo7<T extends number> = T;
|
||||
>Foo7 : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
|
||||
>f7 : <K extends "x">(type: K) => I7[K]
|
||||
>K : K
|
||||
>I7 : I7
|
||||
>type : K
|
||||
>K : K
|
||||
>Foo7 : T
|
||||
>I7 : I7
|
||||
>K : K
|
||||
|
||||
|
||||
@ -629,3 +629,11 @@ class Unbounded<T> {
|
||||
let y: {} | undefined | null = x;
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #23940
|
||||
|
||||
interface I7 {
|
||||
x: any;
|
||||
}
|
||||
type Foo7<T extends number> = T;
|
||||
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user