Typescript: Why the type system does not support the use of property to select subtypes?

Created on 2 Oct 2017  ·  4Comments  ·  Source: microsoft/TypeScript

Only support to use of "index".

type t = {
     a: {
        c: string
    },
    b: string
}

type a1 = t.a;  //error
type a2 = t['a'];  //ok

I must operate many times when I want rename "t['a']".
How to make it more convenient?

Design Limitation

Most helpful comment

The problem with type a1 = t.a is that t might be merged with a namespace with an export named a.
But we should support typed indexed accesses in find-all-references.
EDIT: In typescript@next, we do! So you can rename a to x and we will change to t["x"] as well.

All 4 comments

The problem with type a1 = t.a is that t might be merged with a namespace with an export named a.
But we should support typed indexed accesses in find-all-references.
EDIT: In typescript@next, we do! So you can rename a to x and we will change to t["x"] as well.

Luckily we push you in the right direction thanks to https://github.com/Microsoft/TypeScript/pull/17462

indexedaccess

@andy-ms @DanielRosenwasser I see, thank you all

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Was this page helpful?
0 / 5 - 0 ratings