Skip to content

Commit 0e4288a

Browse files
docs: #219 updated recommend tsconfig.json settings (#215)
1 parent a9a08f3 commit 0e4288a

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

src/pages/docs/resources/typescript.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,40 @@ Greenwood provides built-in support for TypeScript, either through type-strippin
1414
1515
## Setup
1616

17-
The below steps will help you get up and running with TypeScript in your Greenwood project. The general recommendation is to use type-stripping during development for faster live reload, and then run TypeScript during CI (e.g. GitHub Actions) to check and enforce all types, e.g. `tsc --project tsconfig.json`.
17+
The below steps will help you get up and running with TypeScript in your Greenwood project, and are the [same settings](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/init/src/template-base-ts/tsconfig.json) you'll get running [Greenwood's **init** package with TypeScript enabled](/docs/introduction/setup/#init). The general recommendation is to use type-stripping during development for faster live reload, and then run TypeScript during CI (e.g. GitHub Actions) to check and enforce all types, e.g. `tsc --project tsconfig.json`.
1818

1919
1. You will need to use Node **>= 22.6.0** and set the `--experimental-strip-types` flag
2020
1. Install TypeScript into your project, e.g. `npm i typescript --save-dev`
21-
1. Create a _tsconfig.json_ file at the root of your project with these minimum configuration settings. We recommend adding the [`erasableSyntaxOnly` setting](https://www.typescriptlang.org/tsconfig/#erasableSyntaxOnly)
21+
1. Create a _tsconfig.json_ file at the root of your project with the below minimum configuration settings.
22+
1. We also recommend additional configurations like [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax) and [`erasableSyntaxOnly` setting](https://www.typescriptlang.org/tsconfig/#erasableSyntaxOnly)
2223

23-
<!-- prettier-ignore-start -->
24-
25-
<app-ctc-block variant="snippet" heading="tsconfig.json">
24+
<!-- prettier-ignore-start -->
2625

27-
```json
28-
{
29-
"compilerOptions": {
30-
"module": "preserve",
31-
"moduleResolution": "bundler",
32-
"allowImportingTsExtensions": true,
33-
"verbatimModuleSyntax": false,
34-
"noEmit": true
26+
<app-ctc-block variant="snippet" heading="tsconfig.json">
27+
28+
```json5
29+
{
30+
"compilerOptions": {
31+
// minimum required configuration
32+
"target": "es2020", // needs to be at least >= es2015 for `class` support
33+
"module": "preserve",
34+
"moduleResolution": "bundler",
35+
"allowImportingTsExtensions": true,
36+
"noEmit": true,
37+
38+
// additional recommended configuration
39+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
40+
"verbatimModuleSyntax": true,
41+
"erasableSyntaxOnly": true,
42+
},
43+
44+
"exclude": ["./public/", "./greenwood/", "node_modules"],
3545
}
36-
}
37-
```
46+
```
3847

39-
</app-ctc-block>
48+
</app-ctc-block>
4049

41-
<!-- prettier-ignore-end -->
50+
<!-- prettier-ignore-end -->
4251

4352
> _If you're feeling adventurous, you can use **>=23.x** and omit the `--experimental-strip-types` flag_. Keep an eye on [this PR](https://github.com/nodejs/node/pull/57298) for when unflagged type-stripping support may come to Node LTS **22.x**. 👀
4453
@@ -66,6 +75,8 @@ In addition to being able to author your components, SSR pages, and API routes i
6675

6776
<!-- prettier-ignore-end -->
6877

78+
> 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.
79+
6980
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
7081

7182
### Import Attributes

0 commit comments

Comments
 (0)