Skip to content

Commit 064dc8d

Browse files
author
Orta Therox
authored
Merge pull request microsoft#2031 from jablko/patch-3
Add links to tsconfig reference
2 parents fa4d8d2 + e8cd5b4 commit 064dc8d

File tree

87 files changed

+563
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+563
-563
lines changed

packages/documentation/copy/en/declaration-files/Library Structures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ the top-level module object can _never_ be callable.
323323
324324
The most common solution here is to define a `default` export for a callable/constructable object;
325325
module loaders commonly detect this situation automatically and replace the top-level object with the `default` export.
326-
Typescript can handle this for you, if you have [`"esModuleInterop": true`](/tsconfig/#esModuleInterop) in tsconfig.json.
326+
Typescript can handle this for you, if you have [`"esModuleInterop": true`](/tsconfig#esModuleInterop) in tsconfig.json.

packages/documentation/copy/en/declaration-files/Publishing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ There are two main ways you can publish your declaration files to npm:
1111
1. bundling with your npm package
1212
2. publishing to the [@types organization](https://www.npmjs.com/~types) on npm.
1313

14-
If your types are generated by your source code, publish the types with your source code. Both TypeScript and JavaScript projects can generate types via [`--declaration`](/tsconfig#declaration).
14+
If your types are generated by your source code, publish the types with your source code. Both TypeScript and JavaScript projects can generate types via [`declaration`](/tsconfig#declaration).
1515

1616
Otherwise, we recommend submitting the types to DefinitelyTyped, which will publish them to the `@types` organization on npm.
1717

@@ -31,9 +31,9 @@ For example:
3131
}
3232
```
3333

34-
Note that the `"typings"` field is synonymous with `"types"`, and could be used as well.
34+
Note that the `"typings"` field is synonymous with `types`, and could be used as well.
3535

36-
Also note that if your main declaration file is named `index.d.ts` and lives at the root of the package (next to `index.js`) you do not need to mark the `"types"` property, though it is advisable to do so.
36+
Also note that if your main declaration file is named `index.d.ts` and lives at the root of the package (next to `index.js`) you do not need to mark the `types` property, though it is advisable to do so.
3737

3838
## Dependencies
3939

packages/documentation/copy/en/handbook-v1/Basic Types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function warnUser(): void {
274274
}
275275
```
276276

277-
Declaring variables of type `void` is not useful because you can only assign `null` (only if `--strictNullChecks` is not specified, see next section) or `undefined` to them:
277+
Declaring variables of type `void` is not useful because you can only assign `null` (only if [`strictNullChecks`](/tsconfig#strictNullChecks) is not specified, see next section) or `undefined` to them:
278278

279279
```ts twoslash
280280
// @strict: false
@@ -297,13 +297,13 @@ let n: null = null;
297297
By default `null` and `undefined` are subtypes of all other types.
298298
That means you can assign `null` and `undefined` to something like `number`.
299299

300-
However, when using the `--strictNullChecks` flag, `null` and `undefined` are only assignable to `unknown`, `any` and their respective types (the one exception being that `undefined` is also assignable to `void`).
300+
However, when using the [`strictNullChecks`](/tsconfig#strictNullChecks) flag, `null` and `undefined` are only assignable to `unknown`, `any` and their respective types (the one exception being that `undefined` is also assignable to `void`).
301301
This helps avoid _many_ common errors.
302302
In cases where you want to pass in either a `string` or `null` or `undefined`, you can use the union type `string | null | undefined`.
303303

304304
Union types are an advanced topic that we'll cover in a later chapter.
305305

306-
> As a note: we encourage the use of `--strictNullChecks` when possible, but for the purposes of this handbook, we will assume it is turned off.
306+
> As a note: we encourage the use of [`strictNullChecks`](/tsconfig#strictNullChecks) when possible, but for the purposes of this handbook, we will assume it is turned off.
307307
308308
## Never
309309

packages/documentation/copy/en/handbook-v1/Functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ let pickedCard = cardPicker();
313313
alert("card: " + pickedCard.card + " of " + pickedCard.suit);
314314
```
315315

316-
Even better, TypeScript will warn you when you make this mistake if you pass the `--noImplicitThis` flag to the compiler.
316+
Even better, TypeScript will warn you when you make this mistake if you pass the [`noImplicitThis`](/tsconfig#noImplicitThis) flag to the compiler.
317317
It will point out that `this` in `this.suits[pickedSuit]` is of type `any`.
318318

319319
## `this` parameters
@@ -364,7 +364,7 @@ alert("card: " + pickedCard.card + " of " + pickedCard.suit);
364364
```
365365

366366
Now TypeScript knows that `createCardPicker` expects to be called on a `Deck` object.
367-
That means that `this` is of type `Deck` now, not `any`, so `--noImplicitThis` will not cause any errors.
367+
That means that `this` is of type `Deck` now, not `any`, so [`noImplicitThis`](/tsconfig#noImplicitThis) will not cause any errors.
368368

369369
### `this` parameters in callbacks
370370

packages/documentation/copy/en/handbook-v1/Unions and Intersections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function logger(s: NetworkState) {
302302
```
303303

304304
There are two ways to do this.
305-
The first is to turn on `--strictNullChecks` and specify a return type:
305+
The first is to turn on [`strictNullChecks`](/tsconfig#strictNullChecks) and specify a return type:
306306

307307
```ts twoslash
308308
// @errors: 2366
@@ -332,7 +332,7 @@ function logger(s: NetworkState): string {
332332

333333
Because the `switch` is no longer exhaustive, TypeScript is aware that the function could sometimes return `undefined`.
334334
If you have an explicit return type `string`, then you will get an error that the return type is actually `string | undefined`.
335-
However, this method is quite subtle and, besides, [`--strictNullChecks`](/tsconfig#strictNullChecks) does not always work with old code.
335+
However, this method is quite subtle and, besides, [`strictNullChecks`](/tsconfig#strictNullChecks) does not always work with old code.
336336

337337
The second method uses the `never` type that the compiler uses to check for exhaustiveness:
338338

packages/documentation/copy/en/handbook-v2/Basics.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Why should converting it over to TypeScript stop you from running it?
280280

281281
So TypeScript doesn't get in your way.
282282
Of course, over time, you may want to be a bit more defensive against mistakes, and make TypeScript act a bit more strictly.
283-
In that case, you can use the `--noEmitOnError` compiler option.
283+
In that case, you can use the [`noEmitOnError`](/tsconfig#noEmitOnError) compiler option.
284284
Try changing your `hello.ts` file and running `tsc` with that flag:
285285

286286
```sh
@@ -392,7 +392,7 @@ TypeScript has the ability to rewrite code from newer versions of ECMAScript to
392392
This process of moving from a newer or "higher" version of ECMAScript down to an older or "lower" one is sometimes called _downleveling_.
393393

394394
By default TypeScript targets ES3, an extremely old version of ECMAScript.
395-
We could have chosen something a little bit more recent by using the `--target` flag.
395+
We could have chosen something a little bit more recent by using the [`target`](/tsconfig#target) option.
396396
Running with `--target es2015` changes TypeScript to target ECMAScript 2015, meaning code should be able to run wherever ECMAScript 2015 is supported.
397397
So running `tsc --target es2015 hello.ts` gives us the following output:
398398

@@ -421,8 +421,8 @@ This can require a little extra work, but generally speaking it pays for itself
421421
When possible, a new codebase should always turn these strictness checks on.
422422

423423
TypeScript has several type-checking strictness flags that can be turned on or off, and all of our examples will be written with all of them enabled unless otherwise stated.
424-
The `--strict` flag in the CLI, or `"strict": true` in a [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) toggles them all on simultaneously, but we can opt out of them individually.
425-
The two biggest ones you should know about are `noImplicitAny` and `strictNullChecks`.
424+
The [`strict`](/tsconfig#strict) flag in the CLI, or `"strict": true` in a [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) toggles them all on simultaneously, but we can opt out of them individually.
425+
The two biggest ones you should know about are [`noImplicitAny`](/tsconfig#noImplicitAny) and [`strictNullChecks`](/tsconfig#strictNullChecks).
426426

427427
## `noImplicitAny`
428428

@@ -431,10 +431,10 @@ This isn't the worst thing that can happen - after all, falling back to `any` is
431431

432432
However, using `any` often defeats the purpose of using TypeScript in the first place.
433433
The more typed your program is, the more validation and tooling you'll get, meaning you'll run into fewer bugs as you code.
434-
Turning on the `noImplicitAny` flag will issue an error on any variables whose type is implicitly inferred as `any`.
434+
Turning on the [`noImplicitAny`](/tsconfig#noImplicitAny) flag will issue an error on any variables whose type is implicitly inferred as `any`.
435435

436436
## `strictNullChecks`
437437

438438
By default, values like `null` and `undefined` are assignable to any other type.
439439
This can make writing some code easier, but forgetting to handle `null` and `undefined` is the cause of countless bugs in the world - some consider it a [billion dollar mistake](https://www.youtube.com/watch?v=ybrQvs4x0Ps)!
440-
The `strictNullChecks` flag makes handling `null` and `undefined` more explicit, and _spares_ us from worrying about whether we _forgot_ to handle `null` and `undefined`.
440+
The [`strictNullChecks`](/tsconfig#strictNullChecks) flag makes handling `null` and `undefined` more explicit, and _spares_ us from worrying about whether we _forgot_ to handle `null` and `undefined`.

packages/documentation/copy/en/handbook-v2/Classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pt.x = "0";
6969

7070
#### `--strictPropertyInitialization`
7171

72-
The `strictPropertyInitialization` setting controls whether class fields need to be initialized in the constructor.
72+
The [`strictPropertyInitialization`](/tsconfig#strictPropertyInitialization) setting controls whether class fields need to be initialized in the constructor.
7373

7474
```ts twoslash
7575
// @errors: 2564

packages/documentation/copy/en/handbook-v2/Everyday Types.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,17 @@ The `as const` suffix acts like `const` but for the type system, ensuring that a
635635

636636
JavaScript has two primitive values used to signal absent or uninitialized value: `null` and `undefined`.
637637

638-
TypeScript has two corresponding _types_ by the same names. How these types behave depends on whether you have the `strictNullChecks` option on.
638+
TypeScript has two corresponding _types_ by the same names. How these types behave depends on whether you have the [`strictNullChecks`](/tsconfig#strictNullChecks) option on.
639639

640640
### `strictNullChecks` off
641641

642-
With `strictNullChecks` _off_, values that might be `null` or `undefined` can still be accessed normally, and the values `null` and `undefined` can be assigned to a property of any type.
642+
With [`strictNullChecks`](/tsconfig#strictNullChecks) _off_, values that might be `null` or `undefined` can still be accessed normally, and the values `null` and `undefined` can be assigned to a property of any type.
643643
This is similar to how languages without null checks (e.g. C#, Java) behave.
644-
The lack of checking for these values tends to be a major source of bugs; we always recommend people turn `strictNullChecks` on if it's practical to do so in their codebase.
644+
The lack of checking for these values tends to be a major source of bugs; we always recommend people turn [`strictNullChecks`](/tsconfig#strictNullChecks) on if it's practical to do so in their codebase.
645645

646646
### `strictNullChecks` on
647647

648-
With `strictNullChecks` _on_, when a value is `null` or `undefined`, you will need to test for those values before using methods or properties on that value.
648+
With [`strictNullChecks`](/tsconfig#strictNullChecks) _on_, when a value is `null` or `undefined`, you will need to test for those values before using methods or properties on that value.
649649
Just like checking for `undefined` before using an optional property, we can use _narrowing_ to check for values that might be `null`:
650650

651651
```ts twoslash

packages/documentation/copy/en/handbook-v2/Modules.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Conversely, to consume a variable, function, class, interface, etc. exported fro
2727
Before we start, it's important to understand what TypeScript considers a module.
2828
The JavaScript specification declares that any JavaScript files without an `export` or top-level `await` should be considered a script and not a module.
2929

30-
Inside a script file variables and types are declared to be in the shared global scope, and it's assumed that you'll either use the [`--outFile`](/tsconfig#outFile) compiler option to join multiple input files into one output file, or use multiple `<script>` tags in your HTML to load these files (in the correct order!).
30+
Inside a script file variables and types are declared to be in the shared global scope, and it's assumed that you'll either use the [`outFile`](/tsconfig#outFile) compiler option to join multiple input files into one output file, or use multiple `<script>` tags in your HTML to load these files (in the correct order!).
3131

3232
If you have a file that doesn't currently have any `import`s or `export`s, but you want to be treated as a module, add the line:
3333

@@ -306,29 +306,29 @@ squareTwo;
306306

307307
### CommonJS and ES Modules interop
308308

309-
There is a mis-match in features between CommonJS and ES Module because ES Modules only support having the default export as an object, and never as a function. TypeScript has a compiler flag to reduce the friction between the two different sets of constraints with [`esModuleInterop`](/tsconfig/#esModuleInterop).
309+
There is a mis-match in features between CommonJS and ES Module because ES Modules only support having the default export as an object, and never as a function. TypeScript has a compiler flag to reduce the friction between the two different sets of constraints with [`esModuleInterop`](/tsconfig#esModuleInterop).
310310

311311
## TypeScript's Module Resolution Options
312312

313313
Module resolution is the process of taking a string from the `import` or `require` statement, and determining what file that string refers to.
314314

315-
TypeScript includes two resolution strategies: Classic and Node. Classic, the default when the compiler flag [`module`](/tsconfig/#module) is not `commonjs`, is included for backwards compatibility.
315+
TypeScript includes two resolution strategies: Classic and Node. Classic, the default when the compiler option [`module`](/tsconfig#module) is not `commonjs`, is included for backwards compatibility.
316316
The Node strategy replicates how Node.js works in CommonJS mode, with additional checks for `.ts` and `.d.ts`.
317317

318-
There are many TSConfig flags which influence the module strategy within TypeScript: [`moduleResolution`](/tsconfig/#moduleResolution), [`baseUrl`](/tsconfig/#baseUrl), [`paths`](/tsconfig/#paths), [`rootDirs`](/tsconfig/#rootDirs).
318+
There are many TSConfig flags which influence the module strategy within TypeScript: [`moduleResolution`](/tsconfig#moduleResolution), [`baseUrl`](/tsconfig#baseUrl), [`paths`](/tsconfig#paths), [`rootDirs`](/tsconfig#rootDirs).
319319

320320
For the full details on how these strategies work, you can consult the [Module Resolution](/docs/handbook/module-resolution.html).
321321

322322
## TypeScript's Module Output Options
323323

324324
There are two options which affect the emitted JavaScript output:
325325

326-
- [`target`](/tsconfig/#target) which determines which JS features are downleveled (converted to run in older JavaScript runtimes) and which are left intact
327-
- [`module`](/tsconfig/#module) which determines what code is used for modules to interact with each other
326+
- [`target`](/tsconfig#target) which determines which JS features are downleveled (converted to run in older JavaScript runtimes) and which are left intact
327+
- [`module`](/tsconfig#module) which determines what code is used for modules to interact with each other
328328

329-
Which `target` you use is determined by the features available in the JavaScript runtime you expect to run the TypeScript code in. That could be: the oldest web browser you support, the lowest version of Node.js you expect to run on or could come from unique constraints from your runtime - like Electron for example.
329+
Which [`target`](/tsconfig#target) you use is determined by the features available in the JavaScript runtime you expect to run the TypeScript code in. That could be: the oldest web browser you support, the lowest version of Node.js you expect to run on or could come from unique constraints from your runtime - like Electron for example.
330330

331-
All communication between modules happens via a module loader, the compiler flag [`module`](/tsconfig#module) determines which one is used.
331+
All communication between modules happens via a module loader, the compiler option [`module`](/tsconfig#module) determines which one is used.
332332
At runtime the module loader is responsible for locating and executing all dependencies of a module before executing it.
333333

334334
For example, here is a TypeScript file using ES Modules syntax, showcasing a few different options for [`module`](/tsconfig#module):
@@ -378,7 +378,7 @@ export const twoPi = valueOfPi * 2;
378378

379379
> Note that ES2020 is effectively the same as the original `index.ts`.
380380
381-
You can see all of the available options and what their emitted JavaScript code looks like in the [TSConfig Reference for `module`](/tsconfig/#module).
381+
You can see all of the available options and what their emitted JavaScript code looks like in the [TSConfig Reference for `module`](/tsconfig#module).
382382

383383
## TypeScript namespaces
384384

packages/documentation/copy/en/handbook-v2/More on Functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ const args = [8, 5] as const;
751751
const angle = Math.atan2(...args);
752752
```
753753

754-
Using rest arguments may require turning on [`downlevelIteration`](/tsconfig/#downlevelIteration) when targeting older runtimes.
754+
Using rest arguments may require turning on [`downlevelIteration`](/tsconfig#downlevelIteration) when targeting older runtimes.
755755

756756
<!-- TODO link to downlevel iteration -->
757757

0 commit comments

Comments
 (0)