Skip to content

Allow narrowing properties retrieved from types with index signatures #17567

Closed
@kujon

Description

@kujon

TypeScript Version: 2.4.0

Code

type A = {
    [index: string]: [number, number] | null;
};

const value: A = {
    foo: [42, 42]
};

const extractedValue = value.foo !== null ?
    // Object is possibly 'null'.
    value.foo[0] :
    5;

Expected behavior:
Null check is correctly performed and the compiler allows for accessing

Actual behavior:
// Object is possibly 'null'.

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions