Oriel β€” AI & technology worth noticing, every day.

Trick or Type Guard? Surviving `unknown` with is-kit πŸŽƒ

Post Β· https://dev.to/nyaomaru/trick-or-type-guard-surviving-unknown-with-is-kit-4oc2

Hoi hoi! πŸ‘‹ I'm @nyaomaru, a frontend engineer who is scared of horror things πŸ™€ Happy Halloween!...

First seen by Oriel on .

AI summary

A Halloween-themed TypeScript tutorial shows how is-kit composes runtime type guards to validate unknown data, preserve narrowing, and avoid unsafe any assertions.

  • unknown blocks unchecked property access, while isString verifies a runtime value and narrows it to string.
  • struct composes nested guards such as arrayOf, isNumber, optionalKey, and isBoolean; safeParse reports validity without converting invalid data.
  • The pumpkin example accepts extra properties by default, or rejects additional own enumerable string keys with { exact: true }.
  • or combines guards so a value can narrow to string | number, avoiding a monolithic validator.
  • Casting unknown to any bypasses compiler checks but does not change runtime values, allowing invalid operations such as calling toUpperCase on a number.

#typescript #type guards #is-kit

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days Β· Up to 120 recorded samples per source and metric, with reposts kept separate Β· First and latest retained

Reactions

Total public reactions reported by the source; distinct from points and likes.

  • DEV Community: 92, latest observation ; +42 over observed period since

Comments

Comment count reported by the source.

  • DEV Community: 22, latest observation ; +15 over observed period since

Aliases

SourceExternal IDURL
DEV Community4916522https://dev.to/nyaomaru/trick-or-type-guard-surviving-unknown-with-is-kit-4oc2 Read discussion