-
Notifications
You must be signed in to change notification settings - Fork 13k
Properly propagate ObjectFlags.NonInferrableType
onto non-aliased anonymous object types instantiations
#62346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:fix/silent-never-leak-anonymous-object-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+526
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
tests/baselines/reference/nonInferrableTypePropagation4.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
nonInferrableTypePropagation4.ts(15,22): error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: unknown; }>'. | ||
Type 'P<unknown>' is not assignable to type 'P<{ default: unknown; }>'. | ||
Type 'unknown' is not assignable to type '{ default: unknown; }'. | ||
nonInferrableTypePropagation4.ts(25,22): error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<WithDefault<unknown>>'. | ||
Type 'P<unknown>' is not assignable to type 'P<WithDefault<unknown>>'. | ||
Type 'unknown' is not assignable to type 'WithDefault<unknown>'. | ||
nonInferrableTypePropagation4.ts(33,22): error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<[unknown]>'. | ||
Type 'P<unknown>' is not assignable to type 'P<[unknown]>'. | ||
Type 'unknown' is not assignable to type '[unknown]'. | ||
nonInferrableTypePropagation4.ts(41,22): error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: { prop: unknown; }; }>'. | ||
Type 'P<unknown>' is not assignable to type 'P<{ default: { prop: unknown; }; }>'. | ||
Type 'unknown' is not assignable to type '{ default: { prop: unknown; }; }'. | ||
nonInferrableTypePropagation4.ts(49,22): error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: [unknown]; }>'. | ||
Type 'P<unknown>' is not assignable to type 'P<{ default: [unknown]; }>'. | ||
Type 'unknown' is not assignable to type '{ default: [unknown]; }'. | ||
|
||
|
||
==== nonInferrableTypePropagation4.ts (5 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/62345 | ||
|
||
interface P<T> { | ||
then: (onfulfilled: (value: T) => unknown) => unknown; | ||
} | ||
|
||
interface PConstructor { | ||
new <T>(executor: (resolve: (value: T) => void) => void): P<T>; | ||
} | ||
|
||
declare var P: PConstructor; | ||
|
||
declare function foo1<T>(x: () => P<{ default: T }>): T; | ||
|
||
const result1 = foo1(() => { | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: unknown; }>'. | ||
!!! error TS2345: Type 'P<unknown>' is not assignable to type 'P<{ default: unknown; }>'. | ||
!!! error TS2345: Type 'unknown' is not assignable to type '{ default: unknown; }'. | ||
return new P((resolve) => { | ||
resolve; | ||
}); | ||
}); | ||
|
||
type WithDefault<T> = { default: T }; | ||
|
||
declare function foo2<T>(x: () => P<WithDefault<T>>): T; | ||
|
||
const result2 = foo2(() => { | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<WithDefault<unknown>>'. | ||
!!! error TS2345: Type 'P<unknown>' is not assignable to type 'P<WithDefault<unknown>>'. | ||
!!! error TS2345: Type 'unknown' is not assignable to type 'WithDefault<unknown>'. | ||
return new P((resolve) => { | ||
resolve; | ||
}); | ||
}); | ||
|
||
declare function foo3<T>(x: () => P<[T]>): T; | ||
|
||
const result3 = foo3(() => { | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<[unknown]>'. | ||
!!! error TS2345: Type 'P<unknown>' is not assignable to type 'P<[unknown]>'. | ||
!!! error TS2345: Type 'unknown' is not assignable to type '[unknown]'. | ||
return new P((resolve) => { | ||
resolve; | ||
}); | ||
}); | ||
|
||
declare function foo4<T>(x: () => P<{ default: { prop: T } }>): T; | ||
|
||
const result4 = foo4(() => { | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: { prop: unknown; }; }>'. | ||
!!! error TS2345: Type 'P<unknown>' is not assignable to type 'P<{ default: { prop: unknown; }; }>'. | ||
!!! error TS2345: Type 'unknown' is not assignable to type '{ default: { prop: unknown; }; }'. | ||
return new P((resolve) => { | ||
resolve; | ||
}); | ||
}); | ||
|
||
declare function foo5<T>(x: () => P<{ default: [T] }>): T; | ||
|
||
const result5 = foo5(() => { | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '() => P<unknown>' is not assignable to parameter of type '() => P<{ default: [unknown]; }>'. | ||
!!! error TS2345: Type 'P<unknown>' is not assignable to type 'P<{ default: [unknown]; }>'. | ||
!!! error TS2345: Type 'unknown' is not assignable to type '{ default: [unknown]; }'. | ||
return new P((resolve) => { | ||
resolve; | ||
}); | ||
}); | ||
|
154 changes: 154 additions & 0 deletions
154
tests/baselines/reference/nonInferrableTypePropagation4.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
//// [tests/cases/compiler/nonInferrableTypePropagation4.ts] //// | ||
|
||
=== nonInferrableTypePropagation4.ts === | ||
// https://github.com/microsoft/TypeScript/issues/62345 | ||
|
||
interface P<T> { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 2, 12)) | ||
|
||
then: (onfulfilled: (value: T) => unknown) => unknown; | ||
>then : Symbol(P.then, Decl(nonInferrableTypePropagation4.ts, 2, 16)) | ||
>onfulfilled : Symbol(onfulfilled, Decl(nonInferrableTypePropagation4.ts, 3, 9)) | ||
>value : Symbol(value, Decl(nonInferrableTypePropagation4.ts, 3, 23)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 2, 12)) | ||
} | ||
|
||
interface PConstructor { | ||
>PConstructor : Symbol(PConstructor, Decl(nonInferrableTypePropagation4.ts, 4, 1)) | ||
|
||
new <T>(executor: (resolve: (value: T) => void) => void): P<T>; | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) | ||
>executor : Symbol(executor, Decl(nonInferrableTypePropagation4.ts, 7, 10)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 7, 21)) | ||
>value : Symbol(value, Decl(nonInferrableTypePropagation4.ts, 7, 31)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) | ||
} | ||
|
||
declare var P: PConstructor; | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>PConstructor : Symbol(PConstructor, Decl(nonInferrableTypePropagation4.ts, 4, 1)) | ||
|
||
declare function foo1<T>(x: () => P<{ default: T }>): T; | ||
>foo1 : Symbol(foo1, Decl(nonInferrableTypePropagation4.ts, 10, 28)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) | ||
>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 12, 25)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 12, 37)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) | ||
|
||
const result1 = foo1(() => { | ||
>result1 : Symbol(result1, Decl(nonInferrableTypePropagation4.ts, 14, 5)) | ||
>foo1 : Symbol(foo1, Decl(nonInferrableTypePropagation4.ts, 10, 28)) | ||
|
||
return new P((resolve) => { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 15, 16)) | ||
|
||
resolve; | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 15, 16)) | ||
|
||
}); | ||
}); | ||
|
||
type WithDefault<T> = { default: T }; | ||
>WithDefault : Symbol(WithDefault, Decl(nonInferrableTypePropagation4.ts, 18, 3)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 20, 17)) | ||
>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 20, 23)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 20, 17)) | ||
|
||
declare function foo2<T>(x: () => P<WithDefault<T>>): T; | ||
>foo2 : Symbol(foo2, Decl(nonInferrableTypePropagation4.ts, 20, 37)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) | ||
>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 22, 25)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>WithDefault : Symbol(WithDefault, Decl(nonInferrableTypePropagation4.ts, 18, 3)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) | ||
|
||
const result2 = foo2(() => { | ||
>result2 : Symbol(result2, Decl(nonInferrableTypePropagation4.ts, 24, 5)) | ||
>foo2 : Symbol(foo2, Decl(nonInferrableTypePropagation4.ts, 20, 37)) | ||
|
||
return new P((resolve) => { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 25, 16)) | ||
|
||
resolve; | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 25, 16)) | ||
|
||
}); | ||
}); | ||
|
||
declare function foo3<T>(x: () => P<[T]>): T; | ||
>foo3 : Symbol(foo3, Decl(nonInferrableTypePropagation4.ts, 28, 3)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) | ||
>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 30, 25)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) | ||
|
||
const result3 = foo3(() => { | ||
>result3 : Symbol(result3, Decl(nonInferrableTypePropagation4.ts, 32, 5)) | ||
>foo3 : Symbol(foo3, Decl(nonInferrableTypePropagation4.ts, 28, 3)) | ||
|
||
return new P((resolve) => { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 33, 16)) | ||
|
||
resolve; | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 33, 16)) | ||
|
||
}); | ||
}); | ||
|
||
declare function foo4<T>(x: () => P<{ default: { prop: T } }>): T; | ||
>foo4 : Symbol(foo4, Decl(nonInferrableTypePropagation4.ts, 36, 3)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) | ||
>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 38, 25)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 38, 37)) | ||
>prop : Symbol(prop, Decl(nonInferrableTypePropagation4.ts, 38, 48)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) | ||
|
||
const result4 = foo4(() => { | ||
>result4 : Symbol(result4, Decl(nonInferrableTypePropagation4.ts, 40, 5)) | ||
>foo4 : Symbol(foo4, Decl(nonInferrableTypePropagation4.ts, 36, 3)) | ||
|
||
return new P((resolve) => { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 41, 16)) | ||
|
||
resolve; | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 41, 16)) | ||
|
||
}); | ||
}); | ||
|
||
declare function foo5<T>(x: () => P<{ default: [T] }>): T; | ||
>foo5 : Symbol(foo5, Decl(nonInferrableTypePropagation4.ts, 44, 3)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) | ||
>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 46, 25)) | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 46, 37)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) | ||
>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) | ||
|
||
const result5 = foo5(() => { | ||
>result5 : Symbol(result5, Decl(nonInferrableTypePropagation4.ts, 48, 5)) | ||
>foo5 : Symbol(foo5, Decl(nonInferrableTypePropagation4.ts, 44, 3)) | ||
|
||
return new P((resolve) => { | ||
>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 49, 16)) | ||
|
||
resolve; | ||
>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 49, 16)) | ||
|
||
}); | ||
}); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propagating from
typeArguments
is the core of the fix, the rest is just adjusted indentation.You can also find some prior related discussion here: #49887 (comment)