Use typescript 2.1 index access types
Strate opened this issue · 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.
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
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.
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.)
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