-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Describe the bug
const flavorTypeSym = Symbol.for('flavorType')
// https://spin.atomicobject.com/typescript-flexible-nominal-typing/
interface Flavoring<FlavorT> {
[flavorTypeSym]?: FlavorT
}
export type Flavor<T, FlavorT> = T & NoCheck<Flavoring<FlavorT>>
interface Foo {
id: Flavor<number, 'Foo'>
name: string
}
function create(foo: Assert<Foo>): Foo {
return foo
}The id property is completely ignored.
const flavorTypeSym = Symbol.for('flavorType');
function create(foo) {
if (typeof foo !== "object" || foo === null)
throw new Error("Expected foo to be Foo");
if (typeof foo.name !== "string")
throw new Error("Expected foo.name to be a string");
return foo;
}
export {};But when I move NoCheck to the Flavoring type:
interface Flavoring<FlavorT> {
[flavorTypeSym]?: NoCheck<FlavorT>
}
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>it is not ignored and generates an invalid code:
if (id_1.__@flavorTypeSym@801 !== undefined)
^
SyntaxError: Invalid or unexpected token
Expected behavior
I would expect ts-runtime-checks to ignore just Flavoring<FlavorT> and assert that the id property exists and is number.
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels