Skip to content

Index signature arguments are not type checked based on the specialized key type they are constrained to #7660

Description

@malibuzios

TypeScript Version:

1.8.7

Code

type OnlyNumberKeys = {[key: number]: any};
let a: OnlyNumberKeys = {};

a["abcd"] = 1; // No error?
let x = a["abcd"]; // No error?
type OnlyStringKeys = {[key: string]: any};
let b: OnlyStringKeys = {};

b[1234] = 1; // No error?
let y = b[1234]; // No error?

Expected behavior:
Should error

Actual behavior:
Doesn't error

(Sorry if this is a duplicate but a search did not yield anything on this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions