Skip to content

Indexed Accesses Checking Allow Unsafe Assignments #26274

Description

Code

classComponent<S>{state!: S;// assume a default state is provided in some waysetState<KextendskeyofS>(state: Pick<S,K>){/*react-like setState*/}}exportinterfaceState<T>{a: T;}classFoo{}classComp<TextendsFoo,S>extendsComponent<S&State<T>>{foo(a: T){this.setState({a: a});}}

Expected behavior:
Error on setState - a T is not inherently comparable with a S["a"] - since S is unconstrained, so too is S["a"].
For a concrete subtype which exposes the issue, consider:

classBrokenComponentextendsComp<Foo,{a: {x: number}}>{main(){constf=newFoo();this.foo(f);// allowedthis.state.a.x;// According to the typesystem, this should exist, but it won't!}}

Actual behavior:
No error.

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions