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

I don't quite get the point. If the function takes an argument of "hello", "world" or string, doesn't it still just take any string?


The aim here is less about the types (like you say, any string will be valid) and more about autocomplete. When you start a string literal, you can technically type anything in there, but certain answers are more "correct" than others - i.e. these theme colour names. This technique allows you to tell Typescript-as-LSP which names it should suggest, while also letting Typescript-as-typechecker know that other options are also allowed.




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

Search: