HN
Hacker News
Top
New
Best
Ask
Show
Jobs
Comment by pverheggen | Hacker News Reader
Parent
Full thread
pverheggen
·
Why not use annotation instead?
const props: ['foo'] = ['foo']
View on HN
fenomas
·
Didn't occur to me, that's certainly more defensible! Though maybe less humorous.
halflife
·
Or: cons foo = [‘foo’] as const;
wk_end
·
> In a case like that `as const` doesn't work, since the function doesn't expect a readonly argument.
halflife
·
Ah, missed that. Sorry.
cat-whisperer
·
I don’t get this? why do I need to say as const?
afdbcreid
·
`as const` is a special annotation that lets the TypeScript compiler infers the more specific type `["foo"]` instead of `string[]`.
halflife
·
As const creates a typed tuple instead of a typed array
Reply on news.ycombinator.com