0

Is there any opportunity to set advanced type checking to see an error in next example:

type Id = number;

const id: Id = 1;
const notId: number = 2;

function test(val: Id) {
  console.log('val', val);
}

test(id)
test(notId)
Illorian
  • 1,222
  • 2
  • 13
  • 38
  • 2
    TypeScript is _structurally_, not nominally, typed. `type Id = number` is really just making an alias. The way around this is sometimes referred to as _"branded types"_. – jonrsharpe Jan 21 '22 at 11:01
  • It looks more like a hack but as I understood there is no other way – Illorian Jan 21 '22 at 11:07

0 Answers0