schemats icon indicating copy to clipboard operation
schemats copied to clipboard

Use typescript 2.1 index access types

Open Strate opened this issue 8 years ago • 4 comments

Typescript 2.1 introduces index access to types, which can be used to access type of interface property:

interface a {
    prop1: string
    prop2: number
}

let b: a["prop1"] = "321"

This s definetely could be used in schemats to avoid to generate XXXfields namespace.

Strate avatar Feb 25 '17 07:02 Strate

Nice! Not generating XXXfields namespace requires a major version bump. I will first update the examples in README to encourage the use of index access types (#47). Then revisit this issue when we are close to release v2.0

xiamx avatar Feb 25 '17 16:02 xiamx

The limit is that we don't have autocomplete with bracket-notation on index types, yet personnaly I like to use autocomplete. For this reason, perhaps we should not deprecate XXXFields until Typescript allows dot notation to access types ? Nb : TS allows dot notation to properties (not types) with string index signature since only version 2.2, see https://blogs.msdn.microsoft.com/typescript/2017/02/22/announcing-typescript-2-2/ so we can assume they will allow it for types in the future.

abenhamdine avatar Feb 27 '17 11:02 abenhamdine

For this reason, perhaps we should not deprecate XXXFields until Typescript allows dot notation to access types ?

That's an important point. For this reason let's deprecate XXXFields only once TypeScript supports dot notation on interface types. (their language service should be able to provide auto-completion once dot notation is supported.)

xiamx avatar Feb 27 '17 15:02 xiamx

This is particularly relevant when using the (reasonably) new @babel/typescript transform instead of the Typescript compiler, since the Babel transform doesn't support namespaces

bensalilijames avatar Sep 07 '18 09:09 bensalilijames