Relative Content

Tag Archive for typescripttypes

Why is setting a dynamic key unsound in typescript

Context / Reproduction type Example = { a: string, b: number } let value: Example = { a: ‘hello’, b: 10, } // This IIFE is because typescript will narrow the type if assigned directly like // const k: keyof Example = ‘a’ const k = ((): keyof Example => ‘a’)() value = { …value, […]