-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Proposal
https://devblogs.microsoft.com/typescript/announcing-typescript-3-4/#const-assertions
const foo = ([1, 2, 3]: const) // Type is [+1, +2, +3] (how to do read-only elements on tuple?)
const bar = ('foo': const) // Type is 'foo'
const baz = ({foo: 1}: const) // Type is '{| +foo: 1 |}'
Use case
More explicit version of #7607
Also would eliminate need for Object.freeze
as tool for casting to singleton strings
Object.freeze
is also a bit broken with regards to subtyping #7964
Not sure how sound it is, given that it is type cast essentially
Alternative
const foo = Object.freeze('foo') // Type is 'foo'
const baz = Object.freeze(1) // Type is 1
const bar = Object.freeze([1, 2, 3]) // Type is [+1, +2, +3] (how to do read-only elements on tuple?)
kevinbarabash, mrkev, niedzielski, Eliav2 and bpjatfbmrkevmrkev