Effect | Opaque |
Labeled |
---|---|---|
Preserve type name | β | β |
Requires as |
β | β |
declare const label: unique symbol;
export type LabelContainer<Token> = {
readonly [label]?: Token;
// ^ This the only difference between Label and Opaque
};
export type Label<Type, Token = unknown> = Type & LabelContainer<Token>;
Example:
type NormalString = string
type PatternString = Label<string, "PatternString">
type Options = {
prefix: NormalString,
pattern: PatternString,
opaquePattern: OpaquePatternString
}
let options: Options = {
prefix: "foo/",
// ^? (property) prefix: string
pattern: "{bar,baz}"
// ^? (property) pattern: PatternString
}
// No `as PatternString` or `patternString("...")`
let pattern: PatternString = "{bar,baz}"
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