Skip to content

The signature of certain functions do not match the signature of the implementation #55010

Closed as not planned
@NilsIrl

Description

@NilsIrl

Bug Report

Functions such as isArrayType() and isTupleType have a different signature in src/compiler/types.ts and in the implementation in src/checker/types.ts.

In src/compiler/types.ts:

isArrayType(type: Type): boolean;
isTupleType(type: Type): boolean;

In src/compiler/checker.ts:

isTupleType(type: Type): type is TupleTypeReference;
isArrayType(type: Type): type is TypeReference;

This means that the post-condition of these functions cannot be made use of in external code.

🔎 Search Terms

  • isArrayType, isTupleType
  • Signature, TypeChecker

🕗 Version & Regression Information

This was only an internal issue until these functions were exposed in #52467

💻 Code

if (typeChecker.isArrayType(type)) {
    // complains that type is not TypeReference
    typeChecker.getTypeArguments(type);
}

🙁 Actual behavior

TS2345 [ERROR]: Argument of type 'Type' is not assignable to parameter of type 'TypeReference'.
  Type 'Type' is missing the following properties from type 'TypeReference': target, objectFlags
                const typeArgument = checker.getTypeArguments(type);

🙂 Expected behavior

The code example given compiles without issues.

PS: I have a PR ready to be submitted to fix it for these particular functions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions