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

There are a few casts that are allowed that I would consider unsafe, particularly around unions of literals or using empty object literals:

  // No error here
  type Animal = 'dog' | 'cat';
  const notAnimal = 'couch' as Animal;

  // No error here either
  type Food = { isSpicy: boolean };
  const empty = {} as Food;

https://www.typescriptlang.org/play/index.html#code/C4TwDgpg...


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

Search: