Do you have any examples for Opaque
? I thought Opaque
types weren’t supposed to be interchangeable.
import { Opaque } from 'type-fest';
type AccountNumber = Opaque<number>;
type AccountBalance = Opaque<number>;
function getBalance(accountNumber: AccountNumber): AccountBalance {
return 101 as AccountBalance;
}
// pass an AccountBalance instead of an AccountNumber
const ab = 42 as AccountBalance;
console.log(getBalance(ab));
// expected: should not compile
// actual: gets balance for account 42
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too