-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Don't obtain apparent type of contextual types being optional type variables #61635
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/apparent-type-of-contextual-optional-type-variable
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.
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
81 changes: 81 additions & 0 deletions
81
tests/baselines/reference/inferenceFromGenericClass1.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,81 @@ | ||
//// [tests/cases/compiler/inferenceFromGenericClass1.ts] //// | ||
|
||
=== inferenceFromGenericClass1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/61633 | ||
|
||
type AnyConstructor = new (...args: any[]) => object; | ||
>AnyConstructor : Symbol(AnyConstructor, Decl(inferenceFromGenericClass1.ts, 0, 0)) | ||
>args : Symbol(args, Decl(inferenceFromGenericClass1.ts, 2, 27)) | ||
|
||
class Container<T> {} | ||
>Container : Symbol(Container, Decl(inferenceFromGenericClass1.ts, 2, 53)) | ||
>T : Symbol(T, Decl(inferenceFromGenericClass1.ts, 4, 16)) | ||
|
||
declare function RenderFlagsMixin1< | ||
>RenderFlagsMixin1 : Symbol(RenderFlagsMixin1, Decl(inferenceFromGenericClass1.ts, 4, 21)) | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 6, 35)) | ||
>AnyConstructor : Symbol(AnyConstructor, Decl(inferenceFromGenericClass1.ts, 0, 0)) | ||
|
||
>(Base?: BaseClass): BaseClass; | ||
>Base : Symbol(Base, Decl(inferenceFromGenericClass1.ts, 8, 2)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 6, 35)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 6, 35)) | ||
|
||
const result1 = RenderFlagsMixin1(Container); | ||
>result1 : Symbol(result1, Decl(inferenceFromGenericClass1.ts, 10, 5)) | ||
>RenderFlagsMixin1 : Symbol(RenderFlagsMixin1, Decl(inferenceFromGenericClass1.ts, 4, 21)) | ||
>Container : Symbol(Container, Decl(inferenceFromGenericClass1.ts, 2, 53)) | ||
|
||
declare function RenderFlagsMixin2< | ||
>RenderFlagsMixin2 : Symbol(RenderFlagsMixin2, Decl(inferenceFromGenericClass1.ts, 10, 45)) | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 12, 35)) | ||
>AnyConstructor : Symbol(AnyConstructor, Decl(inferenceFromGenericClass1.ts, 0, 0)) | ||
|
||
>(Base: BaseClass): BaseClass; | ||
>Base : Symbol(Base, Decl(inferenceFromGenericClass1.ts, 14, 2)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 12, 35)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 12, 35)) | ||
|
||
const result2 = RenderFlagsMixin2(Container); | ||
>result2 : Symbol(result2, Decl(inferenceFromGenericClass1.ts, 16, 5)) | ||
>RenderFlagsMixin2 : Symbol(RenderFlagsMixin2, Decl(inferenceFromGenericClass1.ts, 10, 45)) | ||
>Container : Symbol(Container, Decl(inferenceFromGenericClass1.ts, 2, 53)) | ||
|
||
declare function RenderFlagsMixin3< | ||
>RenderFlagsMixin3 : Symbol(RenderFlagsMixin3, Decl(inferenceFromGenericClass1.ts, 16, 45)) | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 18, 35)) | ||
>AnyConstructor : Symbol(AnyConstructor, Decl(inferenceFromGenericClass1.ts, 0, 0)) | ||
|
||
>(Base: BaseClass | number): BaseClass; | ||
>Base : Symbol(Base, Decl(inferenceFromGenericClass1.ts, 20, 2)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 18, 35)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 18, 35)) | ||
|
||
const result3 = RenderFlagsMixin3(Container); | ||
>result3 : Symbol(result3, Decl(inferenceFromGenericClass1.ts, 22, 5)) | ||
>RenderFlagsMixin3 : Symbol(RenderFlagsMixin3, Decl(inferenceFromGenericClass1.ts, 16, 45)) | ||
>Container : Symbol(Container, Decl(inferenceFromGenericClass1.ts, 2, 53)) | ||
|
||
declare function RenderFlagsMixin4< | ||
>RenderFlagsMixin4 : Symbol(RenderFlagsMixin4, Decl(inferenceFromGenericClass1.ts, 22, 45)) | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 24, 35)) | ||
>AnyConstructor : Symbol(AnyConstructor, Decl(inferenceFromGenericClass1.ts, 0, 0)) | ||
|
||
>(Base?: BaseClass | number): BaseClass; | ||
>Base : Symbol(Base, Decl(inferenceFromGenericClass1.ts, 26, 2)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 24, 35)) | ||
>BaseClass : Symbol(BaseClass, Decl(inferenceFromGenericClass1.ts, 24, 35)) | ||
|
||
const result4 = RenderFlagsMixin4(Container); | ||
>result4 : Symbol(result4, Decl(inferenceFromGenericClass1.ts, 28, 5)) | ||
>RenderFlagsMixin4 : Symbol(RenderFlagsMixin4, Decl(inferenceFromGenericClass1.ts, 22, 45)) | ||
>Container : Symbol(Container, Decl(inferenceFromGenericClass1.ts, 2, 53)) | ||
|
91 changes: 91 additions & 0 deletions
91
tests/baselines/reference/inferenceFromGenericClass1.types
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,91 @@ | ||
//// [tests/cases/compiler/inferenceFromGenericClass1.ts] //// | ||
|
||
=== inferenceFromGenericClass1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/61633 | ||
|
||
type AnyConstructor = new (...args: any[]) => object; | ||
>AnyConstructor : AnyConstructor | ||
> : ^^^^^^^^^^^^^^ | ||
>args : any[] | ||
> : ^^^^^ | ||
|
||
class Container<T> {} | ||
>Container : Container<T> | ||
> : ^^^^^^^^^^^^ | ||
|
||
declare function RenderFlagsMixin1< | ||
>RenderFlagsMixin1 : <BaseClass extends AnyConstructor | undefined = undefined>(Base?: BaseClass) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ ^^^^^ | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base?: BaseClass): BaseClass; | ||
>Base : BaseClass | undefined | ||
> : ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const result1 = RenderFlagsMixin1(Container); | ||
>result1 : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin1(Container) : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin1 : <BaseClass extends AnyConstructor | undefined = undefined>(Base?: BaseClass) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ ^^^^^ | ||
>Container : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
||
declare function RenderFlagsMixin2< | ||
>RenderFlagsMixin2 : <BaseClass extends AnyConstructor | undefined = undefined>(Base: BaseClass) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^^^ | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base: BaseClass): BaseClass; | ||
>Base : BaseClass | ||
> : ^^^^^^^^^ | ||
|
||
const result2 = RenderFlagsMixin2(Container); | ||
>result2 : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin2(Container) : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin2 : <BaseClass extends AnyConstructor | undefined = undefined>(Base: BaseClass) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^^^ | ||
>Container : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
||
declare function RenderFlagsMixin3< | ||
>RenderFlagsMixin3 : <BaseClass extends AnyConstructor | undefined = undefined>(Base: BaseClass | number) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^^^ | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base: BaseClass | number): BaseClass; | ||
>Base : number | BaseClass | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
|
||
const result3 = RenderFlagsMixin3(Container); | ||
>result3 : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin3(Container) : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin3 : <BaseClass extends AnyConstructor | undefined = undefined>(Base: BaseClass | number) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^^^^ | ||
>Container : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
||
declare function RenderFlagsMixin4< | ||
>RenderFlagsMixin4 : <BaseClass extends AnyConstructor | undefined = undefined>(Base?: BaseClass | number) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ ^^^^^ | ||
|
||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base?: BaseClass | number): BaseClass; | ||
>Base : number | BaseClass | undefined | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const result4 = RenderFlagsMixin4(Container); | ||
>result4 : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin4(Container) : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
>RenderFlagsMixin4 : <BaseClass extends AnyConstructor | undefined = undefined>(Base?: BaseClass | number) => BaseClass | ||
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ ^^^^^ | ||
>Container : typeof Container | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
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,32 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/61633 | ||
|
||
type AnyConstructor = new (...args: any[]) => object; | ||
|
||
class Container<T> {} | ||
|
||
declare function RenderFlagsMixin1< | ||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base?: BaseClass): BaseClass; | ||
|
||
const result1 = RenderFlagsMixin1(Container); | ||
|
||
declare function RenderFlagsMixin2< | ||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base: BaseClass): BaseClass; | ||
|
||
const result2 = RenderFlagsMixin2(Container); | ||
|
||
declare function RenderFlagsMixin3< | ||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base: BaseClass | number): BaseClass; | ||
|
||
const result3 = RenderFlagsMixin3(Container); | ||
|
||
declare function RenderFlagsMixin4< | ||
BaseClass extends AnyConstructor | undefined = undefined, | ||
>(Base?: BaseClass | number): BaseClass; | ||
|
||
const result4 = RenderFlagsMixin4(Container); |
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.
This change replaces the direct check on instantiatedType.flags with a call to maybeTypeOfKind on a non-nullable version of instantiatedType. Please double-check that using getNonNullableType ensures that optional type variables are not incorrectly inferred as type variables.
Copilot uses AI. Check for mistakes.
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.
instantiateTypeWithSingleGenericCallSignature
computedcontextualType
asAnyConstructor | undefined
| undefined
withgetNonNullableType
contextualSignature
from thatanyFunctionType
because this happened withCheckMode.SkipGenericFunctions
anyFunctionType
is non-inferrable,getInferredType
picked up the default type argument (undefined
)getSignatureApplicabilityError
returned with diagnostics because it was called with a check candidate that was a product of signature instantiation with currently inferred type arguments