@uxfront/typescript-config 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +76 -0
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @uxfront/typescript-config
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5bf4d27: Widen the peer ranges to the tool versions the configs work with: `@uxfront/oxfmt-config` now peers on oxfmt `>=0.70.0 <1`, and `@uxfront/oxlint-config` on oxlint `^1.45.0`. Before, the oxfmt peer stopped at 0.70 and the oxlint peer started at 1.85, so a project on a later oxfmt 0.x or an earlier oxlint 1.x got a peer warning and needed an override. `@uxfront/typescript-config` now has a README that lists what it sets and how to extend it.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @uxfront/typescript-config
|
|
2
|
+
|
|
3
|
+
Shared TypeScript configuration for uxfront projects. It type-checks strictly and leaves the output to your bundler, so every project that extends it catches the same mistakes and compiles the same way.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D typescript @uxfront/typescript-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Create a `tsconfig.json` that extends the shared config and lists your own files:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"extends": "@uxfront/typescript-config/tsconfig.json",
|
|
18
|
+
"include": ["src"]
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Keep the `include`: TypeScript resolves an extended config's `include` from the folder that config lives in, so without your own it looks for files inside `node_modules/@uxfront/typescript-config` and stops with `TS18003: No inputs were found`. Override any option under `compilerOptions` in the same file.
|
|
23
|
+
|
|
24
|
+
## What it sets
|
|
25
|
+
|
|
26
|
+
Let's start with strictness, which is where you'll notice the config most:
|
|
27
|
+
|
|
28
|
+
| Option | Value | What it does for you |
|
|
29
|
+
| -------------------------- | ------ | --------------------------------------------------------------------------------------- |
|
|
30
|
+
| `strict` | `true` | Turns on every strict check, like `strictNullChecks` and `noImplicitAny` |
|
|
31
|
+
| `noUncheckedIndexedAccess` | `true` | Types `items[0]` and `record[key]` as possibly `undefined`, so you check before you use |
|
|
32
|
+
| `noImplicitOverride` | `true` | Asks for `override` on a method that replaces one from its base class |
|
|
33
|
+
|
|
34
|
+
Modules are written the way a bundler reads them:
|
|
35
|
+
|
|
36
|
+
| Option | Value | What it does for you |
|
|
37
|
+
| ---------------------- | ------------ | --------------------------------------------------------------------------------------- |
|
|
38
|
+
| `module` | `"preserve"` | Keeps `import` and `export` as you wrote them, and resolves imports the way bundlers do |
|
|
39
|
+
| `verbatimModuleSyntax` | `true` | Asks for `import type` on an import that only brings in types |
|
|
40
|
+
| `isolatedModules` | `true` | Flags code that a tool compiling one file at a time can't compile |
|
|
41
|
+
| `moduleDetection` | `"force"` | Treats every file as a module, even one without `import` or `export` |
|
|
42
|
+
| `esModuleInterop` | `true` | Lets you default-import a CommonJS package |
|
|
43
|
+
| `resolveJsonModule` | `true` | Lets you import a `.json` file, typed from its contents |
|
|
44
|
+
| `allowJs` | `true` | Includes `.js` files in the project |
|
|
45
|
+
|
|
46
|
+
And the target and output:
|
|
47
|
+
|
|
48
|
+
| Option | Value | What it does for you |
|
|
49
|
+
| -------------- | ----------------------------------- | -------------------------------------------------------------------- |
|
|
50
|
+
| `target` | `"es2022"` | Leaves ES2022 syntax, like class fields and top-level `await`, as is |
|
|
51
|
+
| `lib` | `["es2022", "dom", "dom.iterable"]` | Types the ES2022 built-ins and the browser DOM |
|
|
52
|
+
| `noEmit` | `true` | Type-checks only and writes no files |
|
|
53
|
+
| `skipLibCheck` | `true` | Skips type-checking the `.d.ts` files of your dependencies |
|
|
54
|
+
|
|
55
|
+
Two of these are worth a second look:
|
|
56
|
+
|
|
57
|
+
- **`verbatimModuleSyntax`** fails the type-check on `import { Foo } from "./types"` when `Foo` is only a type, with `TS1484`. Write `import type { Foo } from "./types"` instead. [`@uxfront/oxlint-config`](../oxlint-config) has the matching `typescript/consistent-type-imports` rule, so your editor flags it as you type.
|
|
58
|
+
- **`noEmit`** means `tsc` never writes files. A bundler like Vite or a library builder like tsdown compiles your code, and `tsc` only checks it.
|
|
59
|
+
|
|
60
|
+
If you want `tsc` to write the declaration files for a library, turn emit back on for declarations only:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"extends": "@uxfront/typescript-config/tsconfig.json",
|
|
65
|
+
"compilerOptions": {
|
|
66
|
+
"noEmit": false,
|
|
67
|
+
"declaration": true,
|
|
68
|
+
"emitDeclarationOnly": true,
|
|
69
|
+
"rootDir": "src",
|
|
70
|
+
"outDir": "dist"
|
|
71
|
+
},
|
|
72
|
+
"include": ["src"]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This writes a `.d.ts` file to `dist` for each file in `src`, and no JavaScript. Setting `noEmit` to `false` on its own writes a `.js` file beside each source file and no declarations.
|