Open-Source Wikis

/

TypeScript

/

Primitives

/

Signature

microsoft/TypeScript

Signature

The checker's representation of a function or constructor signature: parameters, return type, type parameters, optional/rest indicators, JSDoc, and resolution metadata. A Type representing a function value carries one or more Signatures in its callSignatures and constructSignatures arrays.

Definition

In src/compiler/types.ts:

export interface Signature {
    flags: SignatureFlags;
    /* @internal */ checker?: TypeChecker;
    declaration?: SignatureDeclaration | JSDocSignature;
    typeParameters?: readonly TypeParameter[];
    parameters: readonly Symbol[];
    /* @internal */ thisParameter?: Symbol;
    /* @internal */ resolvedReturnType?: Type;
    /* @internal */ resolvedTypePredicate?: TypePredicate;
    /* @internal */ minArgumentCount: number;
    /* @internal */ resolvedMinArgumentCount?: number;
    /* @internal */ target?: Signature;
    /* @internal */ mapper?: TypeMapper;
    /* @internal */ compositeSignatures?: Signature[];
    /* @internal */ compositeKind?: TypeFlags;
    /* @internal */ erasedSignatureCache?: Signature;
    /* @internal */ canonicalSignatureCache?: Signature;
    /* @internal */ baseSignatureCache?: Signature;
    /* @internal */ optionalCallSignatureCache?: { ... };
    /* @internal */ isolatedSignatureType?: ObjectType;
    /* @internal */ instantiations?: Map<string, Signature>;
}

SignatureFlags

A bit-set covering signature variants:

  • HasRestParameter, HasLiteralTypes
  • Abstract, IsInnerCallChain, IsOuterCallChain, IsUntypedSignatureInJSFile
  • IsNonInferrable, IsSignatureCandidateForOverloadFailure, Construct, Call

Where signatures come from

Every function-shaped declaration becomes one or more signatures:

  • function f(x: number): string {} — one call signature on f's type.
  • class Foo { constructor(x: number); constructor(x: string); constructor(x: any) {} } — two construct signatures (the declaration signatures) plus one implementation signature.
  • interface Foo { (x: number): string; new (x: number): Foo; (x: string): boolean; } — two call signatures and one construct signature on Foo's type.
  • Object methods, arrow functions, accessors, JSDoc @callback types, indexed-access signatures.

The checker constructs signatures from declarations via getSignatureFromDeclaration and caches the result on the declaration's symbol.

Resolution

getSignaturesOfType(type, kind) returns the call or construct signatures for a given object type. The checker may resolve signatures lazily — the resolvedReturnType field is filled in only when first asked for.

For unions of function types, the checker creates a composite signature that intersects the parameter types and unions the return types. compositeSignatures lists the sources.

Overload resolution

resolveCall(node, signatures, candidates, callExpression) is one of the heaviest paths in the checker. Given a call site and a list of candidate signatures, it:

  1. Filters by parameter count (against minArgumentCount / parameter array length).
  2. Filters by this type (when applicable).
  3. For generic candidates, performs type inference using the call's argument types.
  4. Tries assignability of the inferred (or explicit) signature against the arguments.
  5. Picks the most specific matching candidate, or — if none match — picks the closest for diagnostic purposes.

The result is a single Signature (the chosen overload) plus argument-error diagnostics if the call doesn't conform.

Inference

When a generic signature is called with arguments, the checker runs inferTypes(context, source, target, priority) to deduce type-parameter values. Inference is two-pass: it first tries each parameter against its corresponding argument (covariant), then tries this/return positions if context is available.

InferenceContext holds the running state — inferences per type parameter, candidate sets, the choice mode (best, intersect, etc.). After inference, the resulting TypeMapper is applied to produce a fully-specialised Signature.

Type predicates

Signature.resolvedTypePredicate exists for functions like function isString(x: unknown): x is string. The predicate is what makes the function usable as a narrowing guard. The flow walker checks for this when reasoning about an if (isString(x)) block.

Integration points

  • Checker is the sole producer.
  • Language service uses signatures for signatureHelp (parameter hints), hover, completions of optional parameters.
  • Declaration emit prints signatures via the same nodeBuilder mechanism as types.
  • Refactors read signatures when "convert parameters to destructured object" or "infer return type" run.

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Signature – TypeScript wiki | Factory