mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(48542): omit parameter info of contextual union type (#48549)
This commit is contained in:
@@ -307,10 +307,13 @@ namespace ts.SignatureHelp {
|
||||
// for optional function condition.
|
||||
const nonNullableContextualType = contextualType.getNonNullableType();
|
||||
|
||||
const signatures = nonNullableContextualType.getCallSignatures();
|
||||
if (signatures.length !== 1) return undefined;
|
||||
const symbol = nonNullableContextualType.symbol;
|
||||
if (symbol === undefined) return undefined;
|
||||
|
||||
const invocation: ContextualInvocation = { kind: InvocationKind.Contextual, signature: first(signatures), node: startingToken, symbol: chooseBetterSymbol(nonNullableContextualType.symbol) };
|
||||
const signature = lastOrUndefined(nonNullableContextualType.getCallSignatures());
|
||||
if (signature === undefined) return undefined;
|
||||
|
||||
const invocation: ContextualInvocation = { kind: InvocationKind.Contextual, signature, node: startingToken, symbol: chooseBetterSymbol(symbol) };
|
||||
return { isTypeParameterList: false, invocation, argumentsSpan, argumentIndex, argumentCount };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,419 @@
|
||||
[
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/signatureHelp_unionType.ts",
|
||||
"position": 296,
|
||||
"name": "1"
|
||||
},
|
||||
"signatureHelp": {
|
||||
"items": [
|
||||
{
|
||||
"isVariadic": false,
|
||||
"prefixDisplayParts": [
|
||||
{
|
||||
"text": "a",
|
||||
"kind": "localName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
}
|
||||
],
|
||||
"suffixDisplayParts": [
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "void",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"separatorDisplayParts": [
|
||||
{
|
||||
"text": ",",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "fn",
|
||||
"documentation": [],
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "fn",
|
||||
"kind": "parameterName"
|
||||
},
|
||||
{
|
||||
"text": "?",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "x",
|
||||
"kind": "parameterName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "=>",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "|",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "y",
|
||||
"kind": "parameterName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "number",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "=>",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "number",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
}
|
||||
],
|
||||
"isOptional": true,
|
||||
"isRest": false
|
||||
}
|
||||
],
|
||||
"documentation": [],
|
||||
"tags": []
|
||||
}
|
||||
],
|
||||
"applicableSpan": {
|
||||
"start": 295,
|
||||
"length": 31
|
||||
},
|
||||
"selectedItemIndex": 0,
|
||||
"argumentIndex": 0,
|
||||
"argumentCount": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/signatureHelp_unionType.ts",
|
||||
"position": 332,
|
||||
"name": "2"
|
||||
},
|
||||
"signatureHelp": {
|
||||
"items": [
|
||||
{
|
||||
"isVariadic": false,
|
||||
"prefixDisplayParts": [
|
||||
{
|
||||
"text": "b",
|
||||
"kind": "localName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
}
|
||||
],
|
||||
"suffixDisplayParts": [
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "void",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"separatorDisplayParts": [
|
||||
{
|
||||
"text": ",",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x",
|
||||
"documentation": [],
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "x",
|
||||
"kind": "parameterName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "|",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "number",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"isOptional": false,
|
||||
"isRest": false
|
||||
}
|
||||
],
|
||||
"documentation": [],
|
||||
"tags": []
|
||||
}
|
||||
],
|
||||
"applicableSpan": {
|
||||
"start": 332,
|
||||
"length": 0
|
||||
},
|
||||
"selectedItemIndex": 0,
|
||||
"argumentIndex": 0,
|
||||
"argumentCount": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/signatureHelp_unionType.ts",
|
||||
"position": 339,
|
||||
"name": "3"
|
||||
},
|
||||
"signatureHelp": {
|
||||
"items": [
|
||||
{
|
||||
"isVariadic": false,
|
||||
"prefixDisplayParts": [
|
||||
{
|
||||
"text": "Callback",
|
||||
"kind": "interfaceName"
|
||||
},
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
}
|
||||
],
|
||||
"suffixDisplayParts": [
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "|",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "number",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"separatorDisplayParts": [
|
||||
{
|
||||
"text": ",",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x",
|
||||
"documentation": [],
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "x",
|
||||
"kind": "parameterName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "|",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "number",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"isOptional": false,
|
||||
"isRest": false
|
||||
}
|
||||
],
|
||||
"documentation": [],
|
||||
"tags": []
|
||||
}
|
||||
],
|
||||
"applicableSpan": {
|
||||
"start": 339,
|
||||
"length": 0
|
||||
},
|
||||
"selectedItemIndex": 0,
|
||||
"argumentIndex": 0,
|
||||
"argumentCount": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////declare const a: (fn?: ((x: string) => string) | ((y: number) => number)) => void;
|
||||
////declare const b: (x: string | number) => void;
|
||||
////
|
||||
////interface Callback {
|
||||
//// (x: string): string;
|
||||
//// (x: number): number;
|
||||
//// (x: string | number): string | number;
|
||||
////}
|
||||
////declare function c(callback: Callback): void;
|
||||
|
||||
////a((/*1*/) => {
|
||||
//// return undefined;
|
||||
////});
|
||||
////
|
||||
////b(/*2*/);
|
||||
////
|
||||
////c((/*3*/) => {});
|
||||
|
||||
verify.baselineSignatureHelp();
|
||||
Reference in New Issue
Block a user