You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<small><i><ahref='#'>This is a work in progress</a></i></small>
36
-
37
-
38
51
## `package.json` TLDR
39
52
40
53
```jsonc
@@ -52,7 +65,7 @@
52
65
> **Warning** <br />
53
66
> Use at your own discretion
54
67
55
-
### dont use `browser` field
68
+
### Dont use `browser` field
56
69
57
70
webpack's resolve module algorithm picks a more specific field from `package.json` (and other bundlers too), so webpack chooses UMD module from `browser` field on the default and that breaks tree-shaking[^1]
58
71
@@ -390,9 +403,9 @@ Node.js supports a new setting in package.json called type. "type" can be set to
390
403
391
404
Node.js supports two extensions to help with this: `.mjs` and `.cjs`. `.mjs` files are always ES modules, and `.cjs` files are always CommonJS modules, and there’s no way to override these.
392
405
393
-
In turn, TypeScript supports two new source file extensions: .mts and `.cts`. When TypeScript emits these to JavaScript files, it will emit them to `.mjs` and `.cjs` respectively.
406
+
In turn, TypeScript supports two new source file extensions: `.mts` and `.cts`. When TypeScript emits these to JavaScript files, it will emit them to `.mjs` and `.cjs` respectively.
394
407
395
-
Furthermore, TypeScript also supports two new declaration file extensions: .d.mts and .d.cts. When TypeScript generates declaration files for `.mts` and `.cts`, their corresponding extensions will be `.d.mts` and `.d.cts`.
408
+
Furthermore, TypeScript also supports two new declaration file extensions:` .d.mt`s and `.d.cts`. When TypeScript generates declaration files for `.mts` and `.cts`, their corresponding extensions will be `.d.mts` and `.d.cts`.
396
409
397
410
Using these extensions is entirely optional, but will often be useful even if you choose not to use them as part of your primary workflow.
By default (with esModuleInterop false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. In doing this, there are two parts in particular which turned out to be flawed assumptions:
497
+
By default (with `esModuleInterop` false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. In doing this, there are two parts in particular which turned out to be flawed assumptions:
485
498
486
499
a namespace import like `import*asmomentfrom"moment"` acts the same as `const moment = require("moment")`
487
500
@@ -609,7 +622,7 @@ const f: EmptyObject = {}; // NO ERROR - as expected
609
622
610
623
This is ***technically*** safe in this instance, [because under the hood the `{}` type is passed into an intersection type](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6fd37a55773b23e00a19418d9b5aad912087c982/types/react/index.d.ts#L501) (see the note at the end of this comment for why this is safe).
611
624
612
-
However, there is no way for us to statically analyse and know that this is a safe usage.
625
+
However, there is no way for us to statically analyze and know that this is a safe usage.
613
626
To work around this, consider reconfiguring the lint rule to match your repository's coding style.
614
627
You can use the following config to allow it:
615
628
@@ -790,23 +803,23 @@ The following are not valid module specifiers according to the above algorithm:
The method is given a list of module names in a file, and is expected to return an array of size moduleNames.length, each element of the array stores either:
812
+
The method is given a list of module names in a file, and is expected to return an array of size `moduleNames`.length, each element of the array stores either:
800
813
801
-
an instance of ResolvedModule with non-empty property resolvedFileName - resolution for corresponding name from moduleNames array or undefined if module name cannot be resolved.
814
+
an instance of `ResolvedModule` with non-empty property `resolvedFileName` - resolution for corresponding name from moduleNames array or undefined if module name cannot be resolved.
802
815
803
-
You can invoke the standard module resolution process via calling resolveModuleName:
816
+
You can invoke the standard module resolution process via calling `resolveModuleName`:
This function returns an object that stores result of module resolution (value of resolvedModule property) as well as list of file names that were considered candidates before making current decision.
822
+
This function returns an object that stores result of module resolution (value of `resolvedModule` property) as well as list of file names that were considered candidates before making current decision.
810
823
811
824
```typescript
812
825
import * as ts from "typescript";
@@ -891,7 +904,7 @@ Default: `undefined`
891
904
892
905
This option allows you to provide a custom module resolution. The value should point to a JS file that default exports (`export default`, or `module.exports =`, or `export =`) a file with the following interface:
893
906
894
-
```
907
+
```typescript
895
908
interface ModuleResolver {
896
909
version: 1;
897
910
resolveModuleNames(
@@ -903,9 +916,9 @@ interface ModuleResolver {
903
916
): (ts.ResolvedModule | undefined)[];
904
917
}
905
918
```
906
-
Refer to the TypeScript Wiki for an example on how to write the resolveModuleNames function.
919
+
Refer to the TypeScript Wiki for an example on how to write the `resolveModuleNames` function.
907
920
908
-
Note that if you pass custom programs via options.programs this option will not have any effect over them (you can simply add the custom resolution on them directly).
921
+
Note that if you pass custom programs via `options.program`s this option will not have any effect over them (you can simply add the custom resolution on them directly).
0 commit comments