Yep. But that function will accept
type RobotUuid = string;
const bar: RobotUuid = “abc…”;
foo(bar);
This is what duck typing is and specifically my curiosity about being able to de-duck on demand.
type RobotUuid = string;
const bar: RobotUuid = “abc…”;
foo(bar);
This is what duck typing is and specifically my curiosity about being able to de-duck on demand.
Tho I suppose if it is really important you can put an assert there but I'm not familiar with that wrt typescript, maybe the transpiler would kill that?
I've done the occasional type checking in that way in similar languages, it is kind of self documenting too. 90% of the time duck typing is what you want.
Yes, and that’s roughly what TypeScript is: a linter that everyone on your team is running.
assert istype(whatever, MyCustomType)
Which would throw an exception if whatever is not a "MyCustomType" at runtime.