@jmlweb/tsconfig-base 1.0.2 → 1.0.4

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +211 -1
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @jmlweb/tsconfig-base
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a9ece1: Update documentation to use pnpm commands instead of npm
8
+
9
+ ## 1.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 6b73301: Add changelog section with link to CHANGELOG.md in package READMEs
14
+
3
15
  ## 1.0.2
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -18,9 +18,11 @@
18
18
  ## 📦 Installation
19
19
 
20
20
  ```bash
21
- npm install --save-dev @jmlweb/tsconfig-base typescript
21
+ pnpm add -D @jmlweb/tsconfig-base typescript
22
22
  ```
23
23
 
24
+ > 💡 **Upgrading from a previous version?** See the [Migration Guide](#-migration-guide) for breaking changes and upgrade instructions.
25
+
24
26
  ## 🚀 Quick Start
25
27
 
26
28
  Create a `tsconfig.json` file in your project root:
@@ -157,6 +159,44 @@ This base config intentionally omits `include` and `exclude` patterns because:
157
159
  - ✅ Prevents conflicts with project-specific patterns
158
160
  - ✅ More flexible for various project types
159
161
 
162
+ ## 🤔 Why Use This?
163
+
164
+ > **Philosophy**: TypeScript should catch bugs at compile time through strict type checking. If it compiles without errors, it should work correctly.
165
+
166
+ This package provides an opinionated TypeScript configuration that enables all strict flags and additional safety checks. It's designed to prevent common JavaScript pitfalls through TypeScript's type system while remaining flexible enough for any project type.
167
+
168
+ ### Design Decisions
169
+
170
+ **All Strict Flags Enabled (`strict: true` + extras)**: Enables strict null checks, no implicit any, strict function types, etc.
171
+
172
+ - **Why**: TypeScript's strict mode catches entire classes of bugs (null/undefined errors, implicit any holes, binding issues). Additional flags like `noUncheckedIndexedAccess` catch even more edge cases
173
+ - **Trade-off**: More initial type errors when adopting, requires explicit null handling. But this prevents runtime crashes
174
+ - **When to override**: For gradual migration from JavaScript (but aim to enable all flags eventually)
175
+
176
+ **Modern Target (ES2022)**: Compiles to ES2022 with modern JavaScript features
177
+
178
+ - **Why**: Modern Node.js and browsers support ES2022. Using modern features provides better performance and cleaner output. Let your runtime handle the code
179
+ - **Trade-off**: Requires Node.js 18+ or modern browsers. If targeting older environments, override with `ES2020` or lower
180
+ - **When to override**: When supporting legacy environments (but consider transpiling separately)
181
+
182
+ **NodeNext Module Resolution**: Uses Node.js ESM resolution algorithm
183
+
184
+ - **Why**: Matches how Node.js resolves modules in real projects. Prevents module resolution mismatches between TypeScript and runtime
185
+ - **Trade-off**: Requires proper package.json exports and file extensions in imports. But this matches modern JavaScript standards
186
+ - **When to override**: For legacy projects using CommonJS exclusively (but you should migrate to ESM)
187
+
188
+ **No File Inclusion**: Doesn't specify `include` or `exclude` patterns
189
+
190
+ - **Why**: Different projects have different structures (src/, lib/, packages/). Config shouldn't impose opinions about project layout
191
+ - **Trade-off**: Must define your own `include`/`exclude` in project tsconfig.json (but you'd do this anyway for custom needs)
192
+ - **When to override**: Never - add include/exclude in your project's tsconfig.json
193
+
194
+ **Source Maps Enabled**: Generates source maps for debugging
195
+
196
+ - **Why**: Source maps enable debugging TypeScript source in Node.js and browsers. Essential for production debugging
197
+ - **Trade-off**: Slightly larger build output, but negligible compared to debugging benefits
198
+ - **When to override**: If you're absolutely certain you don't need debugging (rare)
199
+
160
200
  ## 🎯 When to Use
161
201
 
162
202
  Use this configuration when you want:
@@ -241,10 +281,180 @@ See real-world usage examples:
241
281
 
242
282
  ## 🔗 Related Packages
243
283
 
284
+ ### Internal Packages
285
+
244
286
  - [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint configuration for TypeScript projects
245
287
  - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier configuration
246
288
  - [`@jmlweb/tsconfig-react`](../tsconfig-react) - TypeScript configuration for React projects
247
289
 
290
+ ### External Tools
291
+
292
+ - [TypeScript](https://www.typescriptlang.org/) - Strongly typed programming language that builds on JavaScript
293
+ - [ts-node](https://typestrong.org/ts-node/) - TypeScript execution engine for Node.js
294
+ - [tsx](https://github.com/privatenumber/tsx) - Fast TypeScript/ESM execution (alternative to ts-node)
295
+ - [ESLint](https://eslint.org/) - Linter for TypeScript (use with @jmlweb/eslint-config-base)
296
+
297
+ ## ⚠️ Common Issues
298
+
299
+ > **Note:** This section documents known issues and their solutions. If you encounter a problem not listed here, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
300
+
301
+ ### Missing File Extensions Error
302
+
303
+ **Symptoms:**
304
+
305
+ - Error: "Relative import paths need explicit file extensions in ECMAScript imports"
306
+ - Import statements like `import { foo } from './bar'` fail
307
+
308
+ **Cause:**
309
+
310
+ - This config uses `moduleResolution: "NodeNext"` which follows Node.js ESM rules
311
+ - Node.js requires explicit `.js` extensions in import statements (even for `.ts` files)
312
+
313
+ **Solution:**
314
+
315
+ Add `.js` extensions to your imports (TypeScript will resolve to `.ts` files):
316
+
317
+ ```typescript
318
+ // Before
319
+ import { foo } from './bar';
320
+
321
+ // After
322
+ import { foo } from './bar.js';
323
+ ```
324
+
325
+ Or switch to a bundler-based module resolution:
326
+
327
+ ```json
328
+ {
329
+ "extends": "@jmlweb/tsconfig-base",
330
+ "compilerOptions": {
331
+ "module": "ESNext",
332
+ "moduleResolution": "bundler"
333
+ }
334
+ }
335
+ ```
336
+
337
+ ### Module and ModuleResolution Mismatch
338
+
339
+ **Symptoms:**
340
+
341
+ - Error: "Option 'module' must be set to 'NodeNext' when 'moduleResolution' is 'NodeNext'"
342
+ - Type errors related to module resolution
343
+
344
+ **Cause:**
345
+
346
+ - Both `module` and `moduleResolution` must be set to compatible values
347
+ - This config uses `NodeNext` for both
348
+
349
+ **Solution:**
350
+
351
+ If you need to override the module system, update both options together:
352
+
353
+ ```json
354
+ {
355
+ "extends": "@jmlweb/tsconfig-base",
356
+ "compilerOptions": {
357
+ "module": "ESNext",
358
+ "moduleResolution": "bundler"
359
+ }
360
+ }
361
+ ```
362
+
363
+ ### CommonJS vs ESM Mismatch
364
+
365
+ **Symptoms:**
366
+
367
+ - Code runs but module resolution is incorrect
368
+ - `require` statements in output when you expected `import`
369
+
370
+ **Cause:**
371
+
372
+ - Your `package.json` has `"type": "module"` but your build uses CommonJS
373
+ - Or vice versa
374
+
375
+ **Solution:**
376
+
377
+ Match your `package.json` to your build output:
378
+
379
+ ```json
380
+ // package.json
381
+ {
382
+ "type": "module" // For ESM output (this config's default)
383
+ }
384
+ ```
385
+
386
+ Or override to CommonJS:
387
+
388
+ ```json
389
+ // tsconfig.json
390
+ {
391
+ "extends": "@jmlweb/tsconfig-base",
392
+ "compilerOptions": {
393
+ "module": "CommonJS",
394
+ "moduleResolution": "node"
395
+ }
396
+ }
397
+ ```
398
+
399
+ ### Index Signature Type Errors
400
+
401
+ **Symptoms:**
402
+
403
+ - Error: "Object is possibly 'undefined'" when accessing object properties
404
+ - Example: `obj[key]` shows type `T | undefined`
405
+
406
+ **Cause:**
407
+
408
+ - This config enables `noUncheckedIndexedAccess` for extra safety
409
+ - TypeScript correctly adds `undefined` to index access types
410
+
411
+ **Solution:**
412
+
413
+ Use optional chaining or explicit checks:
414
+
415
+ ```typescript
416
+ // Before
417
+ const value = obj[key].toString();
418
+
419
+ // After - option 1: optional chaining
420
+ const value = obj[key]?.toString();
421
+
422
+ // After - option 2: explicit check
423
+ if (obj[key] !== undefined) {
424
+ const value = obj[key].toString();
425
+ }
426
+
427
+ // After - option 3: type assertion (use sparingly)
428
+ const value = obj[key]!.toString();
429
+ ```
430
+
431
+ Or disable this strict check:
432
+
433
+ ```json
434
+ {
435
+ "extends": "@jmlweb/tsconfig-base",
436
+ "compilerOptions": {
437
+ "noUncheckedIndexedAccess": false
438
+ }
439
+ }
440
+ ```
441
+
442
+ ## 🔄 Migration Guide
443
+
444
+ ### Upgrading to a New Version
445
+
446
+ > **Note:** If no breaking changes were introduced in a version, it's safe to upgrade without additional steps.
447
+
448
+ **No breaking changes have been introduced yet.** This package follows semantic versioning. When breaking changes are introduced, detailed migration instructions will be provided here.
449
+
450
+ For version history, see the [Changelog](./CHANGELOG.md).
451
+
452
+ **Need Help?** If you encounter issues during migration, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
453
+
454
+ ## 📜 Changelog
455
+
456
+ See [CHANGELOG.md](./CHANGELOG.md) for version history and release notes.
457
+
248
458
  ## 📄 License
249
459
 
250
460
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jmlweb/tsconfig-base",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Base TypeScript configuration with strict type checking and modern defaults",
5
5
  "main": "tsconfig.json",
6
6
  "exports": {