Skip to content

Improve string literal completions for property values when a partially-typed string fixes inference to a type parameter #51770

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Dec 5, 2022

Makes further improvements to what was implemented here: #48410

cc @andrewbranch

…ly-typed string fixes inference to a type parameter
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 5, 2022
@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.

/// <reference path="fourslash.ts" />

// @Filename: /a.tsx
//// declare function bar1<P extends "" | "bar" | "baz">(p: { type: P }): void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice how this test is almost identical to the one here:
https://github.com/microsoft/TypeScript/pull/48811/files#diff-a3a2637795672382fb54d54c328d2aff49256e2ce89a12cc7b5e636da2dd48ce

the only difference is that the argument here is p: { type: P } where that linked one uses p: P

}
case SyntaxKind.CaseClause:
return (parent as CaseClause).expression === node ? getSwitchedType(parent as CaseClause, checker) : undefined;
default:
return checker.getContextualType(node);
return checker.getContextualType(node, contextFlags);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added test case only relies on this one. However, I've passed around contextFlags to all other checker.getContextualType calls in this function for consistency

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants