News for hackers. Stuff that matters.
Re:Parse, Don't Validate (2019) by mixedCase on Saturday June 26, 2021 @09:57AM (#27641893)
FWIW, you can achieve row polymorphism in TypeScript, although it's not super intuitive.

  function rowPolymorphic<R extends { a: number }>(record: R): R & { a: string } {
    return {
      ...record,
      a: record.a.toString(),
    }
  }

  const rec = rowPolymorphic({
    a: 123,
    b: "string",
  })
  console.log(rec.b)

There are no comments on this comment yet.