-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
It can create lots of new types easily and structurally.
function build<N, T>() {
return <{
(a: N & T): void;
(a: T): N & T;
}>((a: T) => a);
}
namespace Types {
export namespace Nominal1 {
class Nominal<T> {
private NOMINAL: T;
}
export type A = Nominal<'A'> & number;
export const A = build<Nominal<'A'>, number>();
export type B = Nominal<'B'> & number;
export const B = build<Nominal<'B'>, number>();
}
}
namespace Types {
export namespace Nominal2 {
class Nominal<T> {
private NOMINAL: T;
}
export type A = Nominal<'A'> & number;
export const A = build<Nominal<'A'>, number>();
export type B = Nominal<'B'> & number;
export const B = build<Nominal<'B'>, number>();
}
}
var a1: Types.Nominal1.A;
var b1: Types.Nominal1.B;
var a2: Types.Nominal2.A;
a1 = b1; // error
a1 = a2; // error
a1 = Types.Nominal1.A(0); // ok
a1 = Types.Nominal1.A(a1); // error
a1 = Types.Nominal1.B(0); // error
a1 = Types.Nominal2.A(0); // error
zpdDG4gta8XKpMCd
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created