3 ms·
But you have to care about the type with unknown? For instance calling this on an unknown obj.value Will return a type error that value doesn’t exist on
by edgyquant 4y ago
But you have to care about the type with unknown? For instance calling this on an unknown
obj.value
Will return a type error that value doesn’t exist on unknown. While calling it on an ant is valid typing
- thoughtspile 4y agoHere, you expect obj to have a property called "value", so I'd say you do care about the type of obj. A valid type would be obj: { value: blah }
- _greim_ 4y ago> But you have to care about the type with unknown? It's better to say `unknown` is a promise that you won't care about the type. When you write `obj.value`, you're caring about the type. TypeScript sees that and says "hey, you promised you wouldn't care about this type." > While calling it on an ant is valid typing It's still invalid, same as if you'd used `unknown`. It just suppresses the type error. The presence of `any` in a codebase is a very real risk. The only reason it exists is to allow incremental porting from JavaScript to TypeScript.