Skip to content

Cannot read property 'kind' of undefined at Object.parenthesizeArrayTypeMember #26153

Closed
@victorwelling

Description

@victorwelling

TypeScript Version: 3.1.0-dev.20180802

Search Terms:

  • Cannot read property 'kind' of undefined
  • Optional element in tuple
  • ReadonlyArray
  • Strict mode

Code

type Foo = [object, object?];

const bar: ReadonlyArray<Foo> = [{}, {}];

Expected behavior:
An error along the lines of:

Type '{}[]' is not assignable to type '[object, (object | undefined)?][]

Actual behavior:

./node_modules/typescript/lib/tsc.js:67968
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at Object.parenthesizeArrayTypeMember (./node_modules/typescript/lib/tsc.js:50576:24)
    at Object.createOptionalTypeNode (./node_modules/typescript/lib/tsc.js:47850:24)
    at typeReferenceToTypeNode (./node_modules/typescript/lib/tsc.js:26572:44)
    at typeToTypeNodeHelper (./node_modules/typescript/lib/tsc.js:26383:28)
    at typeReferenceToTypeNode (./node_modules/typescript/lib/tsc.js:26560:43)
    at typeToTypeNodeHelper (./node_modules/typescript/lib/tsc.js:26383:28)
    at signatureToSignatureDeclarationHelper (./node_modules/typescript/lib/tsc.js:26827:52)
    at createTypeNodesFromResolvedType (./node_modules/typescript/lib/tsc.js:26666:43)
    at createTypeNodeFromObjectType (./node_modules/typescript/lib/tsc.js:26547:35)
    at createAnonymousTypeNode (./node_modules/typescript/lib/tsc.js:26502:42)

Conditions
It seems this bug is only triggered if:

  • a ReadonlyArray is used – Array doesn't seem to trigger it
  • strict mode is enabled
  • the last element of the tuple is optional

Playground Link:
Playground. Be sure to enable strictNullChecks to replicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions