Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/docs/types/custom-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ interface PartialPerson

This way TypeScript always keeps the `interface` in-tact, allowing Nitrogen to properly process it.

## Cyclic references are not supported

Direct or indirect cyclic struct references are not supported:

```ts title="Direct cycle ❌"
interface Node {
child: Node
}
```

```ts title="Indirect cycle ❌"
interface A {
b: B
}
interface B {
a: A
}
```

## Structs are eagerly converted

Since structs are just flat value types, each key/value is eagerly converted from a JS value to a native value (and vice-versa) when passing them between JS and native.
Expand Down
8 changes: 8 additions & 0 deletions packages/nitrogen/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
if (typeof error !== 'object') {
return `${error}`
}
if (error instanceof RangeError && error.message.includes('Maximum call stack size exceeded')) {

Check warning on line 38 in packages/nitrogen/src/utils.ts

View workflow job for this annotation

GitHub Actions / Lint TypeScript (eslint, prettier)

Replace `error·instanceof·RangeError·&&·error.message.includes('Maximum·call·stack·size·exceeded')` with `⏎····error·instanceof·RangeError·&&⏎····error.message.includes('Maximum·call·stack·size·exceeded')⏎··`
return (
`${error.name}: ${error.message}\n` +
`This is likely caused by a direct or indirect cyclic struct reference ` +
`(e.g. \`interface Node { child: Node }\` or \`interface A { b: B }\` and \`interface B { a: A }\`).\n` +
`See: https://nitro.margelo.com/docs/types/custom-structs#cyclic-references-are-not-supported`
)
}
if (error instanceof Error) {
let message = `${error.name}: ${error.message}`
if (error.cause != null) {
Expand Down
Loading