Skip to content

Static index signatures do not ensure consistency across index kinds within the same classΒ #44082

Closed
@weswigham

Description

@weswigham

⏯ Playground Link

Playground link

πŸ’» Code

// non-static equivalent, for reference
class Q {
    readonly [s: string]: number;
    readonly [s: number]: 42 | 233
}

class W extends Q {
    readonly [s: string]: number
}

class EW extends W {
    readonly [s: string]: boolean
    readonly [s: number]: 1 
}

// static example
class B {
    static readonly [s: string]: number;
    static readonly [s: number]: 42 | 233
}

class D extends B {
    static readonly [s: string]: number
}

class ED extends D {
    static readonly [s: string]: boolean
    static readonly [s: number]: 1 // should error, 1 isn't assignable to `boolean`!
}

πŸ™ Actual behavior

No error.

πŸ™‚ Expected behavior

Numeric index type '1' is not assignable to string index type 'boolean'.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions