Skip to content

Type checking bug (Type 'null' cannot be used as an index type) #20434

Closed
@mbrodersen

Description

@mbrodersen

TypeScript Version: 2.5.3

Code

if(columnIndex === null) return (_:number) => null;

return (rowIndex:number) => table.rows[rowIndex].rowValues[columnIndex];

Expected behavior:

No type errors.

Actual behavior:

error TS2538: Type 'null' cannot be used as an index type.

(referring to the columnIndex variable captured by the lambda expression)

Work around:

The type error goes away if I instead do:

return (rowIndex:number) => table.rows[rowIndex].rowValues[columnIndex as number];

However that shouldn't be necessary.

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