Skip to content

Commit 6f8418f

Browse files
docs: document caveat with greenwood nested type imports and side effects (#262)
1 parent 2265eeb commit 6f8418f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/pages/docs/resources/typescript.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ In addition to being able to author your components, SSR pages, and API routes i
7272

7373
<!-- prettier-ignore-end -->
7474

75-
> We recommend putting the `type` on the outside of the braces to avoid [inadvertent bundling](https://github.com/ProjectEvergreen/greenwood/issues/1576) of the package your importing from.
76-
7775
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
7876

7977
### Import Attributes
@@ -95,3 +93,17 @@ Currently TypeScript only supports types for standard [JSON Import Attributes](h
9593
</app-ctc-block>
9694

9795
<!-- prettier-ignore-end -->
96+
97+
## Type Imports
98+
99+
Due to how bundlers and other [type-aware tools handle `type` based imports](https://github.com/ProjectEvergreen/greenwood/issues/1576#issuecomment-3795821236), you will need to make sure the `type` qualifier is at the _**top level**_ of the import statement so as to prevent side-effectful import statements from being left behind and included in your bundles.
100+
101+
```ts
102+
// ✅ DO THIS
103+
import type { Page } from "@greenwood/cli";
104+
105+
// ❌ NOT THIS
106+
import { type Page } from "@greenwood/cli";
107+
```
108+
109+
> There is a helpful [**typescript-eslint** rule](https://typescript-eslint.io/rules/no-import-type-side-effects/) for ensuring predictable behaviors around this syntax.

0 commit comments

Comments
 (0)