Skip to content

isArrayType declared internally returns type is TypeReference however the converse is not true #55510

Closed as not planned
@NilsIrl

Description

@NilsIrl

⚙ Compilation target

N/A

⚙ Library

N/A

Missing / Incorrect Definition

From src/compiler/checker.ts:

isArrayType(type: Type): type is TypeReference;

This implies that if isArrayType returns false then type is not a TypeReference which may not be the case as pointed out by #55010 (comment).

If instead an interface ArrayType was added like so:

interface ArrayType extends TypeReference {}

and isArrayType updated like so:

isArrayType(type: Type): type is ArrayType;

Then the signature would be safe and correct. This will then allow the externally available compiler API to match the internal one. Currently because the internal signature of isArrayType is not safe the external signature instead is:

isArrayType(type: Type): boolean;

Sample Code

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

Documentation Link

Continuation of #55010

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions