#infer type not working properly?
12 messages · Page 1 of 1 (latest)
instead it seems its using {case:1} but wrong inferring
const x: Untagged<Tagged<number, "u8", { minValue: 0; maxValue: 255 }>> = 0;
this works
More cases
Preview:```ts
declare const tags: unique symbol
export type Tagged<
BaseType,
Tag extends PropertyKey,
Metadata = void
= BaseType & {
[tags]: {[K in Tag]: Metadata}
}
export type u8 = Tagged<
number,
"u8",
{minValue: 0; maxValue: 255}
export type Untagged<T> = T extends Tagged<
infer Base,
never,
never
? Base | {case: 1}
: T
...```
@bold ginkgo Yeah, it seems the infer only works if Tag is actually set to the right type in the infer clause:
declare const tags: unique symbol;
type Untag<T, Tags> = T extends (infer Base) & {[tags]: Tags } ? Base : never;
type Test = number & {[tags]: string };
type T1 = Untag<Test, string>; // number
type T2 = Untag<Test, never>; // never
type T3 = Untag<Test, any>; // Test
type T4 = Untag<Test, unknown> // Test
Not sure if this is some necessary aspect of how infer works or if this is a bug.
looks like some bug to me
Could you do:
export type Untagged<T> = Omit<T, typeof tags>
instead?
i ended up like that