What does the following ‘const’ type parameter (TypeScript 5.0) infer? function identity(value: T): T { return value; } const result = identity({ x: 1, y: ‘hello’ });

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following ‘const’ type parameter (TypeScript 5.0) infer? function identity(value: T): T { return value; } const result = identity({ x: 1, y: ‘hello’ });

Key points

  • Const inference in TypeScript 5.0 results in readonly properties
  • Narrow literal types are inferred to maintain specific values
  • The 'const' keyword restricts modifications to the inferred type

Ready to go further?

Related questions