mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(50224): Intellisense for strings within a type's Union doesn't work properly for JSX (#50231)
* fix(50224): show string literal completions in JsxAttributeInitializer * add feedback changes
This commit is contained in:
parent
6ee5db95c2
commit
44ce3cff70
@ -241,7 +241,7 @@ namespace ts.Completions.StringCompletions {
|
||||
// Get string literal completions from specialized signatures of the target
|
||||
// i.e. declare function f(a: 'A');
|
||||
// f("/*completion position*/")
|
||||
return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) : fromContextualType();
|
||||
return argumentInfo && getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType();
|
||||
}
|
||||
// falls through (is `require("")` or `require(""` or `import("")`)
|
||||
|
||||
@ -283,7 +283,7 @@ namespace ts.Completions.StringCompletions {
|
||||
type !== current && isLiteralTypeNode(type) && isStringLiteral(type.literal) ? type.literal.text : undefined);
|
||||
}
|
||||
|
||||
function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker): StringLiteralCompletionsFromTypes {
|
||||
function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker): StringLiteralCompletionsFromTypes | undefined {
|
||||
let isNewIdentifier = false;
|
||||
const uniques = new Map<string, true>();
|
||||
const candidates: Signature[] = [];
|
||||
@ -301,8 +301,7 @@ namespace ts.Completions.StringCompletions {
|
||||
isNewIdentifier = isNewIdentifier || !!(type.flags & TypeFlags.String);
|
||||
return getStringLiteralTypes(type, uniques);
|
||||
});
|
||||
|
||||
return { kind: StringLiteralCompletionKind.Types, types, isNewIdentifier };
|
||||
return length(types) ? { kind: StringLiteralCompletionKind.Types, types, isNewIdentifier } : undefined;
|
||||
}
|
||||
|
||||
function stringLiteralCompletionsFromProperties(type: Type | undefined): StringLiteralCompletionsFromProperties | undefined {
|
||||
|
||||
@ -4,4 +4,4 @@
|
||||
////declare function f(a: string, b: number): void;
|
||||
////f("/**/", 0);
|
||||
|
||||
verify.completions({ marker: "", exact: [], isNewIdentifierLocation: true });
|
||||
verify.completions({ marker: "", exact: [], isNewIdentifierLocation: false });
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @jsx: preserve
|
||||
// @filename: /a.tsx
|
||||
////type Props = { a: number } | { b: "somethingelse" };
|
||||
////declare function Foo(args: Props): any
|
||||
////
|
||||
////const a1 = <Foo b={"/*1*/"} />
|
||||
////const a2 = <Foo b="/*2*/" />
|
||||
|
||||
verify.completions({ marker: ["1", "2"], exact: ["somethingelse"] });
|
||||
Loading…
x
Reference in New Issue
Block a user