This repository was archived by the owner on Apr 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
2. Enum and Union types overriding
Selene edited this page Mar 30, 2023
·
1 revision
Cuetsy allows to override parent values when we are extending the interfaces.
- You can override a union type value with another different as long it belongs to the parent union type.
- You can set a value from the parent type.
- You can set a default value from the parent type.
CUE | TypeScript |
---|---|
UnionType: "a" | "b" | "c" @cuetsy(kind="type")
ExtendedUnionType: "d" | "e" | "f" | UnionType @cuetsy(kind="type")
Parent: {
defaultValue: ExtendedUnionType
myUnionType: ExtendedUnionType
myUnionTypeValue: ExtendedUnionType
} @cuetsy(kind="interface")
Interface: {
Parent
defaultValue: ExtendedUnionType & (*"e" | _)
myUnionType: UnionType
myUnionTypeValue: ExtendedUnionType & "e"
} @cuetsy(kind="interface")
|
export type UnionType = ('a' | 'b' | 'c');
export type ExtendedUnionType = ('d' | 'e' | 'f' | UnionType);
export interface Parent {
defaultValue: ExtendedUnionType;
myUnionType: ExtendedUnionType;
myUnionTypeValue: ExtendedUnionType;
}
export interface Interface {
defaultValue: UnionType;
myUnionType: UnionType;
myUnionTypeValue: 'e';
}
export const defaultInterface = {
defaultValue: 'e',
}; |
CUE | TypeScript |
---|---|
Enum: "a" | "b" | "c" @cuetsy(kind="enum")
Parent: {
defaultValue: Enum
enumValue: Enum
} @cuetsy(kind="interface")
Interface: {
Parent
defaultValue: Enum & (*"a" | _)
enumValue: Enum & "a"
} @cuetsy(kind="interface")
|
export enum Enum {
A = 'a',
B = 'b',
C = 'c',
}
export interface Parent {
defaultValue: Enum;
enumValue: Enum;
}
export interface Interface {
defaultValue: Enum;
enumValue: Enum.A;
}
export const defaultInterface = {
defaultValue: Enum.A,
}; |