A common misconception is that TypeScript "knows" what every JS function does. It doesn't -- it just has type definitions in .d.ts files, and type definitions can't always represent all the semantic information about a function's behavior
Comments
Log in with your Bluesky account to leave a comment
e.g. Array#find has a signature that takes a callback and returns T | undefined. But the type definition for find doesn't encode anything about the relationship between the callback and the return value. TS can't "know" that if the callback always returns false, find always returns undefined
It's the same situation as these three functions -- from TS's perspective, when you call them, they are *identical* despite all having different internal behavior. Not all internal behavior has a corresponding representation in the type system (yet 😉)
Comments