DEV Community

Discussion on: Using JavaScript Symbol.toStringTag for objects types description

Collapse
 
aminnairi profile image
Amin • Edited
type User = { name: string }
const user = { name: 'john' }

Object.defineProperty(user, "name", {
  value: undefined
});

alert(user.name.length); // Cannot read property 'length' of undefined (in JavaScript after transpilation)
Enter fullscreen mode Exit fullscreen mode

This compiles just fine in TypeScript and even gives an error in the playground when run.

Collapse
 
ninofiliu profile image
Nino Filiu

Sure, but come on, that's just deliberately trying to deceive TypeScript at this point ^^