Skip to content

Commit

Permalink
Fix allowed and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spinillos committed Feb 10, 2023
1 parent f776edd commit f614e6f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ func (g *generator) genEnum(name string, v cue.Value) []ts.Decl {
op, _ = v.Expr()
}

// We restrict the expression of TS enums to CUE disjunctions (sum types) of strings.
allowed := cue.StringKind | cue.NumberKind | cue.NumberKind
// We restrict the expression of TS enums to ints or strings.
allowed := cue.StringKind | cue.IntKind
ik := v.IncompleteKind()
if ik&allowed != ik {
g.addErr(valError(v, "typescript enums may only be generated from a disjunction of concrete int with memberNames attribute or strings"))
g.addErr(valError(v, "typescript enums may only be generated from concrete strings, or ints with memberNames attribute"))
return nil
}

Expand Down
27 changes: 27 additions & 0 deletions testdata/multi_level_type_extension.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- cue --

#AType: "a" | "b" | "c" @cuetsy(kind="type")
#BType: "d" | "e" | "f" | #AType @cuetsy(kind="type")

#Base: {
type: #AType
} @cuetsy(kind="interface")

#Struct: {
#Base
type: #BType
} @cuetsy(kind="interface")

-- ts --

export type AType = ('a' | 'b' | 'c');

export type BType = ('d' | 'e' | 'f' | AType);

export interface Base {
type: AType;
}

export interface Struct extends Base {
type: BType;
}
2 changes: 1 addition & 1 deletion testdata/struct_enum_error.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ TableCellDisplayMode: {
} @cuetsy(kind="enum")

-- err --
typescript enums may only be generated from a disjunction of concrete int with memberNames attribute or strings
typescript enums may only be generated from concrete strings, or ints with memberNames attribute"

0 comments on commit f614e6f

Please sign in to comment.