Skip to content

Commit 371fa74

Browse files
author
Brad Anderson
committed
rework createType to allow isStringLiteral()
1 parent 65ca052 commit 371fa74

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

packages/nitrogen/src/nitrogen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function runNitrogen({
115115
` ⚙️ Generating specs for HybridObject "${chalk.bold(moduleName)}"...`
116116
)
117117

118-
// Create all files and throw it into a big lsit
118+
// Create all files and throw it into a big list
119119
const allFiles = platforms
120120
.flatMap((p) => {
121121
const language = platformSpec[p]!

packages/nitrogen/src/syntax/createType.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function createType(type: TSMorphType, isOptional: boolean): Type {
153153
return createType(type.getBaseTypeOfLiteralType(), isOptional)
154154
}
155155
return new NumberType()
156-
} else if (type.isString()) {
156+
} else if (type.isString() || type.isStringLiteral()) {
157157
return new StringType()
158158
} else if (type.isBigInt() || type.isBigIntLiteral()) {
159159
return new BigIntType()
@@ -232,7 +232,7 @@ export function createType(type: TSMorphType, isOptional: boolean): Type {
232232
variants = removeDuplicates(variants)
233233

234234
if (variants.length === 1) {
235-
// It's just one type with undefined/null varians - so we treat it like a simple optional.
235+
// It's just one type with undefined/null variant - so we treat it like a simple optional.
236236
return variants[0]!
237237
}
238238

@@ -257,10 +257,6 @@ export function createType(type: TSMorphType, isOptional: boolean): Type {
257257
throw new Error(
258258
`Anonymous objects cannot be represented in C++! Extract "${type.getText()}" to a separate interface/type declaration.`
259259
)
260-
} else if (type.isStringLiteral()) {
261-
throw new Error(
262-
`String literal ${type.getText()} cannot be represented in C++ because it is ambiguous between a string and a discriminating union enum.`
263-
)
264260
} else {
265261
throw new Error(
266262
`The TypeScript type "${type.getText()}" cannot be represented in C++!`

0 commit comments

Comments
 (0)