Skip to content
0:00 / 0:00

#typescript#typenarrowing#inoperator

TypeScript 4.9 - Unlisted Property Narrowing with the `in` Operator | Release Report

Michigan TypeScript

22K subscribers • 12 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.

Intermediate. Assumes working knowledge.

1.6K views3 years ago1 recommendation

Programming languagesTypeScript

An explanation of how TypeScript 4.9 improves type narrowing when checking for unlisted properties using the in operator.

TypeScript does lots of different things to "narrow" the type of a variable based on the checks in your code. This creates a situation where you would normally thing you'd then be able to access a variable that you just asserted exists, but unfortunately TypeScript didn't work that way. Except that now it does! TypeScript 4.9 introduces some very handy optimizations for better understanding your code when doing this kind of type narrowing. Introduction Unlisted Property Narrowing with the `in` operator looking at the example the problem (prior to 4.9) `Record` with "property-key-being-checked" and unknown how the solution looks in practice audience comment: `unknown` is better than `any` audience question: is this related to `useUnknownInCatchVariables`? audience comment: react-query (i.e. tanstack-query) Error wrapping Recorded on November 1st 2022 at Cahoots (cahoots.com) in Ann Arbor, Michigan.

Why it's here

1 person recommends this

What people say. Recommended as a helpful explanation of the quality-of-life improvements in TypeScript 4.9.

u/dimitropoulosin r/typescript • Recommends

On “Announcing TypeScript 4.9”

Exciting stuff! I'm most excited for the property narrowing with the \`in\` operator because it's such a quality-of-life improvement. On that note, though, Michigan TypeScript developers has videos on some other of the new features in 4.9 as well: * TypeScript satisfies operator in Storybook * TypeScript 4.9 Checks for Equality on NaN * TypeScript's satisfies operator: Intro to 4.9's new feature