Because opaque.d.ts
is not module file, unique symbol tag of the Opaque
type is exposed
Also, the typescript compiler does not regard following as an error.
import {Opaque} from 'type-fest'
import {tag} from 'type-fest/source/opaque';
type AccountNumber = Opaque<number, 'AccountNumber'>;
declare const accountNumber: AccountNumber
accountNumber[tag]
I suggest adding export {}
in opaque.d.ts
. (This is added if use typescript compiler.)
// ...
export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
export {}
Then, the typescript compiler complains that the tag is not exported.
import {Opaque} from 'type-fest'
import {tag} from 'type-fest/source/opaque'; // Error: Module '"type-fest/source/opaque"' declares 'tag' locally, but it is not exported.ts(2459)
type AccountNumber = Opaque<number, 'AccountNumber'>;
declare const accountNumber: AccountNumber
accountNumber[tag] // Error: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Number & Tagged<"z">'.ts(7053)
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