Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why not use annotation instead?

  const props: ['foo'] = ['foo']


Didn't occur to me, that's certainly more defensible! Though maybe less humorous.


Or: cons foo = [‘foo’] as const;


> In a case like that `as const` doesn't work, since the function doesn't expect a readonly argument.


Ah, missed that. Sorry.


I don’t get this? why do I need to say as const?


`as const` is a special annotation that lets the TypeScript compiler infers the more specific type `["foo"]` instead of `string[]`.


As const creates a typed tuple instead of a typed array




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: