typeholes / tserr

A problems view for TypeScript errors
12 stars 0 forks source link

Branded type aware errors #20

Open typeholes opened 1 year ago

typeholes commented 1 year ago

For example, the error message here doesn't point you towards needing a branded type

type FileName = string & {__brand: 'FN'};

type Errs = Record<FileName, string>;

const foo: Errs = {
  ['a' as 'a' & {__brand: 'FN'}]: 1,
  b: 1
}
Type '{ [x: string]: number; b: number; }' is not assignable to type 'Errs'.
  Object literal may only specify known properties, and 'b' does not exist in type 'Errs'.(2322)

It should be fairly easy to detect the branded type key and report something like

   Property 'b' is not branded 'FileName'