Skip to content

Commit

Permalink
feat: Throw a better error message when using wrong imports (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy authored Jan 8, 2025
1 parent bf19f7d commit 96e7716
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/nitrogen/src/syntax/createType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,19 @@ export function createType(
`String literal ${type.getText()} cannot be represented in C++ because it is ambiguous between a string and a discriminating union enum.`
)
} else {
throw new Error(
`The TypeScript type "${type.getText()}" cannot be represented in C++!`
)
if (type.getSymbol() == null) {
// There is no declaration for it!
// Could be an invalid import, e.g. an alias
throw new Error(
`The TypeScript type "${type.getText()}" cannot be resolved - is it imported properly? ` +
`Make sure to import it properly using fully specified relative or absolute imports, no aliases.`
)
} else {
// A different error
throw new Error(
`The TypeScript type "${type.getText()}" cannot be represented in C++!`
)
}
}
}

Expand Down

0 comments on commit 96e7716

Please sign in to comment.