Skip to content

Commit 3b28100

Browse files
committed
Unwrap substitutions both before _and_ after potential simplification
1 parent d9f0212 commit 3b28100

5 files changed

+181
-0
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12788,6 +12788,14 @@ namespace ts {
1278812788
if (target.flags & TypeFlags.Simplifiable) {
1278912789
target = getSimplifiedType(target, /*writing*/ true);
1279012790
}
12791+
if (source.flags & TypeFlags.Substitution) {
12792+
source = (<SubstitutionType>source).substitute;
12793+
}
12794+
if (target.flags & TypeFlags.Substitution) {
12795+
target = (<SubstitutionType>target).typeVariable;
12796+
}
12797+
Debug.assert(!(source.flags & TypeFlags.Substitution), "Source type was a substitution - substitutes are unhandled in relationship checking");
12798+
Debug.assert(!(target.flags & TypeFlags.Substitution), "Target type was a substitution - substitutes are unhandled in relationship checking");
1279112799

1279212800
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
1279312801
// If so, reporting the `null` and `undefined` in the type is hardly useful.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts]
2+
type AnyFunction = (...args: any[]) => any;
3+
type Params<T> = Parameters<Extract<T, AnyFunction>>;
4+
5+
interface Wrapper<T> {
6+
call<K extends keyof T>(event: K, ...args: Params<T[K]>): void;
7+
}
8+
9+
interface AWrapped {
10+
foo(): void;
11+
}
12+
13+
class A {
14+
foo: Wrapper<AWrapped>;
15+
}
16+
17+
interface BWrapped extends AWrapped {
18+
bar(): void;
19+
}
20+
21+
class B extends A {
22+
foo: Wrapper<BWrapped>;
23+
}
24+
25+
//// [indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.js]
26+
var __extends = (this && this.__extends) || (function () {
27+
var extendStatics = function (d, b) {
28+
extendStatics = Object.setPrototypeOf ||
29+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
30+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
31+
return extendStatics(d, b);
32+
};
33+
return function (d, b) {
34+
extendStatics(d, b);
35+
function __() { this.constructor = d; }
36+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37+
};
38+
})();
39+
var A = /** @class */ (function () {
40+
function A() {
41+
}
42+
return A;
43+
}());
44+
var B = /** @class */ (function (_super) {
45+
__extends(B, _super);
46+
function B() {
47+
return _super !== null && _super.apply(this, arguments) || this;
48+
}
49+
return B;
50+
}(A));
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
=== tests/cases/compiler/indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts ===
2+
type AnyFunction = (...args: any[]) => any;
3+
>AnyFunction : Symbol(AnyFunction, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 0, 0))
4+
>args : Symbol(args, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 0, 20))
5+
6+
type Params<T> = Parameters<Extract<T, AnyFunction>>;
7+
>Params : Symbol(Params, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 0, 43))
8+
>T : Symbol(T, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 1, 12))
9+
>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --))
10+
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
11+
>T : Symbol(T, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 1, 12))
12+
>AnyFunction : Symbol(AnyFunction, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 0, 0))
13+
14+
interface Wrapper<T> {
15+
>Wrapper : Symbol(Wrapper, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 1, 53))
16+
>T : Symbol(T, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 3, 18))
17+
18+
call<K extends keyof T>(event: K, ...args: Params<T[K]>): void;
19+
>call : Symbol(Wrapper.call, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 3, 22))
20+
>K : Symbol(K, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 4, 6))
21+
>T : Symbol(T, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 3, 18))
22+
>event : Symbol(event, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 4, 25))
23+
>K : Symbol(K, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 4, 6))
24+
>args : Symbol(args, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 4, 34))
25+
>Params : Symbol(Params, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 0, 43))
26+
>T : Symbol(T, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 3, 18))
27+
>K : Symbol(K, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 4, 6))
28+
}
29+
30+
interface AWrapped {
31+
>AWrapped : Symbol(AWrapped, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 5, 1))
32+
33+
foo(): void;
34+
>foo : Symbol(AWrapped.foo, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 7, 20))
35+
}
36+
37+
class A {
38+
>A : Symbol(A, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 9, 1))
39+
40+
foo: Wrapper<AWrapped>;
41+
>foo : Symbol(A.foo, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 11, 9))
42+
>Wrapper : Symbol(Wrapper, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 1, 53))
43+
>AWrapped : Symbol(AWrapped, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 5, 1))
44+
}
45+
46+
interface BWrapped extends AWrapped {
47+
>BWrapped : Symbol(BWrapped, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 13, 1))
48+
>AWrapped : Symbol(AWrapped, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 5, 1))
49+
50+
bar(): void;
51+
>bar : Symbol(BWrapped.bar, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 15, 37))
52+
}
53+
54+
class B extends A {
55+
>B : Symbol(B, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 17, 1))
56+
>A : Symbol(A, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 9, 1))
57+
58+
foo: Wrapper<BWrapped>;
59+
>foo : Symbol(B.foo, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 19, 19))
60+
>Wrapper : Symbol(Wrapper, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 1, 53))
61+
>BWrapped : Symbol(BWrapped, Decl(indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts, 13, 1))
62+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/compiler/indexedAccessKeyofNestedSimplifiedSubstituteUnwrapped.ts ===
2+
type AnyFunction = (...args: any[]) => any;
3+
>AnyFunction : AnyFunction
4+
>args : any[]
5+
6+
type Params<T> = Parameters<Extract<T, AnyFunction>>;
7+
>Params : Parameters<Extract<T, AnyFunction>>
8+
9+
interface Wrapper<T> {
10+
call<K extends keyof T>(event: K, ...args: Params<T[K]>): void;
11+
>call : <K extends keyof T>(event: K, ...args: Parameters<Extract<T[K], AnyFunction>>) => void
12+
>event : K
13+
>args : Parameters<Extract<T[K], AnyFunction>>
14+
}
15+
16+
interface AWrapped {
17+
foo(): void;
18+
>foo : () => void
19+
}
20+
21+
class A {
22+
>A : A
23+
24+
foo: Wrapper<AWrapped>;
25+
>foo : Wrapper<AWrapped>
26+
}
27+
28+
interface BWrapped extends AWrapped {
29+
bar(): void;
30+
>bar : () => void
31+
}
32+
33+
class B extends A {
34+
>B : B
35+
>A : A
36+
37+
foo: Wrapper<BWrapped>;
38+
>foo : Wrapper<BWrapped>
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type AnyFunction = (...args: any[]) => any;
2+
type Params<T> = Parameters<Extract<T, AnyFunction>>;
3+
4+
interface Wrapper<T> {
5+
call<K extends keyof T>(event: K, ...args: Params<T[K]>): void;
6+
}
7+
8+
interface AWrapped {
9+
foo(): void;
10+
}
11+
12+
class A {
13+
foo: Wrapper<AWrapped>;
14+
}
15+
16+
interface BWrapped extends AWrapped {
17+
bar(): void;
18+
}
19+
20+
class B extends A {
21+
foo: Wrapper<BWrapped>;
22+
}

0 commit comments

Comments
 (0)