Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Oct 18, 2024

fixes #60253

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 18, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@@ -5637,6 +5637,7 @@ export function getPropertiesForObjectExpression(contextualType: Type, completio
}

function getApparentProperties(type: Type, node: ObjectLiteralExpression | JsxAttributes, checker: TypeChecker) {
type = checker.unwrapNoInferType(type);
Copy link
Contributor Author

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 since NoInfers 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 a NoInfer 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 NoInfers 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 NoInfers 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

NoInfer breaks discriminate union autocomplete
2 participants