Merge pull request #26140 from Kingwl/completionUnionType
improve completions for union type in type arguments
This commit is contained in:
commit
2b83b67aa3
2 changed files with 14 additions and 0 deletions
|
@ -402,6 +402,8 @@ namespace ts.Completions {
|
||||||
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((node.parent.parent as IndexedAccessTypeNode).objectType));
|
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((node.parent.parent as IndexedAccessTypeNode).objectType));
|
||||||
case SyntaxKind.ImportType:
|
case SyntaxKind.ImportType:
|
||||||
return { kind: StringLiteralCompletionKind.Paths, paths: PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker) };
|
return { kind: StringLiteralCompletionKind.Paths, paths: PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker) };
|
||||||
|
case SyntaxKind.UnionType:
|
||||||
|
return isTypeReferenceNode(node.parent.parent.parent) ? { kind: StringLiteralCompletionKind.Types, types: getStringLiteralTypes(typeChecker.getTypeArgumentConstraint(node.parent.parent as UnionTypeNode)), isNewIdentifier: false } : undefined;
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
12
tests/cases/fourslash/completionListForStringUnion.ts
Normal file
12
tests/cases/fourslash/completionListForStringUnion.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
//// type A = 'fooooo' | 'barrrrr';
|
||||||
|
//// type B<T extends A> = {};
|
||||||
|
//// type C = B<'fooooo' | '/**/'>
|
||||||
|
|
||||||
|
|
||||||
|
goTo.marker();
|
||||||
|
verify.completionListContains("fooooo");
|
||||||
|
verify.completionListContains("barrrrr");
|
||||||
|
edit.insert("b");
|
||||||
|
verify.completionListContains("barrrrr");
|
Loading…
Reference in a new issue