DEV Community

Discussion on: The Typescript "as const" trick

Collapse
 
orta profile image
Orta • Edited

Nope, looks like the JSDoc types parser doesn't know about as const at all, you'd need to re-type it inside an @types to get the literal types

/** @type {Readonly<{ b: "thingy"}>} */
const b = {
  b: "thingy"
}

b.b // will be "thingy" in the type system
Enter fullscreen mode Exit fullscreen mode
Collapse
 
adamcoster profile image
Adam Coster

Yep, that's the headache I've been trying to avoid. It seems that with Typescript it's generally possible to avoid DRY violations between types and expressions, but it's pretty hard to avoid with JSDoc.