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

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


> 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.


Here, 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 }




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: