-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fixed member completions for NoInfer
-wrapped unions
#60271
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:fix/no-infer-union-completions
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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,41 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @strict: true | ||
// @jsx: preserve | ||
|
||
// @Filename: /a.tsx | ||
//// /// <reference path="/.lib/react18/react18.d.ts" /> | ||
//// /// <reference path="/.lib/react18/global.d.ts" /> | ||
//// | ||
//// interface A { | ||
//// type: "a"; | ||
//// value: string; | ||
//// } | ||
//// | ||
//// interface B { | ||
//// type: "b"; | ||
//// size: number; | ||
//// } | ||
//// | ||
//// type Union = A | B; | ||
//// | ||
//// function accept1<T extends Union>(union: NoInfer<T>) {} | ||
//// accept1({ /*1*/ }); | ||
//// accept1({ type: "a", /*2*/ }); | ||
//// | ||
//// function accept2<T extends Union>(arg: { prop: NoInfer<T> }) {} | ||
//// accept2({ prop: { /*3*/ } }); | ||
//// accept2({ prop: { type: "a", /*4*/ } }); | ||
//// | ||
//// function Accept3<T extends Union>(props: NoInfer<T>) {} | ||
//// <Accept3 /*5*/ />; | ||
//// <Accept3 type="a" /*6*/ />; | ||
|
||
verify.completions({ | ||
marker: ["1", "3", "5"], | ||
exact: ["size", "type", "value"], | ||
}); | ||
verify.completions({ | ||
marker: ["2", "4", "6"], | ||
exact: ["value"], | ||
}); |
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.
At first, I considered unwrapping it in the public
getContextualType
(and alikes). But sinceNoInfer
s are not unwrapped when they contain structured types etc it wouldn't really address everything.My line of thinking was that the API user likely shouldn't be concerned with
NoInfer
types all that much and it would be simpler if they just wouldn't be observable by the API users. But currently they will always be - we can obtain{ prop: NoInfer<A> }
, then get that property and end up with aNoInfer
type easily.So it's pretty impractical to unwrap those in the API layer, there are just too many places where the user interacts with the types and, perhaps, my initial instinct that
NoInfer
s should be hidden from the API users wasn't good anyway.So I decided I might very well just uwrap it here since that's something than an external API user would have to do anyway. It feels utterly annoying to deal with those
NoInfer
s though. I'd expect most of the "get me a type" calls have to be wrapped with this unwrapping call. It's such an easy mistake to make.But, in general,
NoInfer<Structured>
types behave almost the same as their wrapped base types. So I'm thinking now that maybe it's just the union case that gets in a way as that's not a union per-se but yet it's also a union for actual practical purposes.So perhaps a better fix would be to distribute
NoInfer
over unions? That has some drawbacks for huge unions as we'd produce an equally huge distributed output union though.