This page documents the signature help service, which powers the parameter hint UI in editors. When a user types inside a function call or type argument list, the service identifies the invocation context, retrieves candidate signatures from the type checker, and returns a SignatureHelpItems structure that editors render as a popup showing parameter names and documentation.
For related editor features, see Code Completions and Find References and Rename. For the language service host that drives all these features, see Language Service.
The public API is the function getSignatureHelpItems exported from src/services/signatureHelp.ts153-195 The language service (LanguageService interface defined in src/services/types.ts5115-5277) exposes this via its getSignatureHelpItems method, which editors call when the user types inside a function call.
Function signature:
| Parameter | Type | Purpose |
|---|---|---|
program | Program | Provides the type checker via program.getTypeChecker() and source files. |
sourceFile | SourceFile | The file containing the cursor. |
position | number | Cursor offset (character index) in the file. |
triggerReason | SignatureHelpTriggerReason | undefined | Discriminated union: SignatureHelpInvokedReason, SignatureHelpCharacterTypedReason, or SignatureHelpRetriggeredReason. |
The SignatureHelpTriggerReason types are defined in src/services/types.ts4618-4638 and indicate:
invoked: User explicitly requested help (e.g., Ctrl+Shift+Space).characterTyped: User typed a trigger character ((, ,, <).retrigger: Signature help was already active and is being updated.Sources: src/services/signatureHelp.ts153-195 src/services/types.ts4618-4638 src/services/types.ts5115-5277
Diagram: getSignatureHelpItems execution flow
This diagram shows the function call chain within the services layer. Key decision points include trigger character validation src/services/signatureHelp.ts167-175 finding the argument context src/services/signatureHelp.ts618-629 and resolving candidate signatures from the type checker src/services/signatureHelp.ts253-305
Sources: src/services/signatureHelp.ts153-305
The service distinguishes three kinds of invocation context, expressed by the const enum InvocationKind src/services/signatureHelp.ts96-100 and the Invocation discriminated union src/services/signatureHelp.ts101-115:
InvocationKind | Interface | Applies To | Key Field |
|---|---|---|---|
Call | CallInvocation | Regular calls, new expressions, JSX elements, tagged templates | node: CallLikeExpression |
TypeArgs | TypeArgsInvocation | Type argument lists Foo<T, …> before the ( | called: Identifier |
Contextual | ContextualInvocation | Parameters inferred from contextual function types | signature: Signature, symbol: Symbol |
Diagram: Invocation discriminated union and InvocationKind enum
The Invocation type is a discriminated union defined in src/services/signatureHelp.ts101-115 The kind field is the discriminant. Type narrowing on invocation.kind allows accessing specific fields like CallLikeExpression for regular calls src/compiler/types.ts2854
Sources: src/services/signatureHelp.ts96-115 src/compiler/types.ts2854
ArgumentListInfo defined in src/services/signatureHelp.ts121-127 is the central intermediate structure. It captures the cursor's position within an argument list before the type checker is consulted.
Type definition:
| Field | Type | Meaning |
|---|---|---|
kind | ArgumentListKind | TypeArguments or CallArguments src/services/signatureHelp.ts117-120 |
invocation | Invocation | Discriminated union identifying the call site kind. |
argumentsSpan | TextSpan | The text range over which this signature help session is active. |
argumentIndex | number | Zero-based index of the argument the cursor is on. |
argumentCount | number | Total number of arguments provided so far. |
Sources: src/services/signatureHelp.ts117-127
getContainingArgumentInfosrc/services/signatureHelp.ts618-629 walks up the AST from the token at the cursor position. It calls getImmediatelyContainingArgumentOrContextualParameterInfo at each level.
getImmediatelyContainingArgumentInfosrc/services/signatureHelp.ts315-397 handles AST shapes that host signature help:
| AST Pattern | How Detected | Notes |
|---|---|---|
| Call / new expression | isCallOrNewExpression(parent) | Handles both type-arg and value-arg lists. |
| JSX opening element | isJsxOpeningLikeElement(parent) | Arg index = 0; count = 1 src/services/signatureHelp.ts348-353 |
Bare <T> type args | getPossibleTypeArgumentsInfo | Produces TypeArgsInvocation src/services/signatureHelp.ts581-616 |
tryGetParameterInfo src/services/signatureHelp.ts411-430 handles the case where the cursor is inside a function expression being passed as an argument. It uses getContextualType from the checker to retrieve the expected function type.
Diagram: AST node types mapped to InvocationKind
Sources: src/services/signatureHelp.ts315-430 src/services/signatureHelp.ts581-616
getCandidateOrTypeInfo src/services/signatureHelp.ts253-305 converts an ArgumentListInfo into CandidateInfo or TypeInfo.
Key type checker integration:
For InvocationKind.Call, the service calls checker.getResolvedSignatureForSignatureHelp src/services/signatureHelp.ts262 This function, defined in src/compiler/checker.ts31346-31393 populates an array of all overload signatures and returns the best-matching one.
For InvocationKind.TypeArgs without callable signatures, it falls back to checker.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias src/services/signatureHelp.ts297
Sources: src/services/signatureHelp.ts253-305 src/compiler/checker.ts31346-31393
getArgumentIndexOrCount src/services/signatureHelp.ts500-540 iterates over children of the argument list. Non-comma children are counted as arguments. Spread elements are counted via getSpreadElementCount src/services/signatureHelp.ts479-490 which inspects the spread's type; if it is a fixed-length tuple, the number of elements is added.
Sources: src/services/signatureHelp.ts479-540
createSignatureHelpItemssrc/services/signatureHelp.ts647-696 maps candidate Signature objects to SignatureHelpItem values.
| Function | Location | Role |
|---|---|---|
getSignatureHelpItem | src/services/signatureHelp.ts724-733 | Converts one Signature → SignatureHelpItem[]. |
itemInfoForParameters | src/services/signatureHelp.ts771-789 | Builds display parts for value parameter lists. |
itemInfoForTypeParameters | src/services/signatureHelp.ts756-769 | Builds display parts for type parameter lists. |
The NodeBuilderFlags used when printing types include OmitParameterModifiers, IgnoreErrors, and UseAliasDefinedOutsideCurrentScope src/services/signatureHelp.ts646
Sources: src/services/signatureHelp.ts646-789
When a signature has a rest parameter, createSignatureHelpItems src/services/signatureHelp.ts685-694 adjusts the argumentIndex. If the rest parameter is not the final parameter, no parameter is highlighted. Otherwise, the index is clamped to the last parameter to keep highlighting on the rest parameter for additional arguments.
Sources: src/services/signatureHelp.ts685-694
Diagram: Complete signature help pipeline
Sources: src/services/signatureHelp.ts153-696 src/compiler/checker.ts31346-31393
Refresh this wiki