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

Require at least a single match when defining discriminable properties #53654

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ import {
isDynamicName,
isEffectiveExternalModule,
isElementAccessExpression,
isEmptyStringLiteral,
isEntityName,
isEntityNameExpression,
isEnumConst,
Expand Down Expand Up @@ -29246,6 +29247,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function isPossiblyDiscriminantValue(node: Expression): boolean {
switch (node.kind) {
case SyntaxKind.StringLiteral:
return !isEmptyStringLiteral(node as StringLiteral);
MariaSolOs marked this conversation as resolved.
Show resolved Hide resolved
MariaSolOs marked this conversation as resolved.
Show resolved Hide resolved
case SyntaxKind.NumericLiteral:
case SyntaxKind.BigIntLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/fourslash/completionsUnionProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference path="fourslash.ts" />

//// type Foo = { a: 0, b: 'x' } | { a: 0, b: 'y' } | { a: 1, b: 'z' };
//// const foo: Foo = { a: 0, b: '/**/

verify.completions({ marker: "", triggerCharacter: "'", includes: [ "x", "y" ], excludes: [ "z" ] });
MariaSolOs marked this conversation as resolved.
Show resolved Hide resolved