Skip to content

Commit

Permalink
Adds support for showing the tsconfig info in the website, and adds i…
Browse files Browse the repository at this point in the history
…t to a bunch of docs
  • Loading branch information
orta committed Aug 23, 2020
1 parent 3cc9786 commit 0bbfda2
Show file tree
Hide file tree
Showing 66 changed files with 531 additions and 465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `--watch` implementation of the compiler relies on using `fs.watch` and `fs.

## Configuring file watching using a `tsconfig.json`

```json
```json tsconfig
{
// Some typical compiler options
"compilerOptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Project references can solve all of these problems and more.

`tsconfig.json` files have a new top-level property, `references`. It's an array of objects that specifies projects to reference:

```js
```js tsconfig
{
"compilerOptions": {
// The usual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Example `tsconfig.json` files:

- Using the `"files"` property

```json
```json tsconfig
{
"compilerOptions": {
"module": "commonjs",
Expand Down Expand Up @@ -57,7 +57,7 @@ Example `tsconfig.json` files:

- Using the `"include"` and `"exclude"` properties

```json
```json tsconfig
{
"compilerOptions": {
"module": "system",
Expand All @@ -77,9 +77,9 @@ Example `tsconfig.json` files:
Depending on the JavaScript runtime environment which you intend to run your code in, there may be a base configuration which you can use at [github.com/tsconfig/bases](https://github.com/tsconfig/bases/).
These are `tsconfig.json` files which your project extends from which simplifies your `tsconfig.json` by handling the runtime support.

For example, if you were writing a project which uses Node.js version 12 and above, then you could use the npm module [`@tsconfig/node12`](https://www.npmjs.com/package/@tsconfig/node12)
For example, if you were writing a project which uses Node.js version 12 and above, then you could use the npm module [`@tsconfig/node12`](https://www.npmjs.com/package/@tsconfig/node12):

```json
```json tsconfig
{
"extends": "@tsconfig/node12/tsconfig.json",

Expand Down
4 changes: 2 additions & 2 deletions packages/documentation/copy/en/reference/Decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tsc --target ES5 --experimentalDecorators

**tsconfig.json**:

```json
```json tsconfig
{
"compilerOptions": {
"target": "ES5",
Expand Down Expand Up @@ -482,7 +482,7 @@ tsc --target ES5 --experimentalDecorators --emitDecoratorMetadata

**tsconfig.json**:

```json
```json tsconfig
{
"compilerOptions": {
"target": "ES5",
Expand Down
8 changes: 4 additions & 4 deletions packages/documentation/copy/en/reference/Module Resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Loaders use a mapping configuration to map module names to files at run-time, se
The TypeScript compiler supports the declaration of such mappings using `"paths"` property in `tsconfig.json` files.
Here is an example for how to specify the `"paths"` property for `jquery`.

```json
```json tsconfig
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
Expand Down Expand Up @@ -258,7 +258,7 @@ projectRoot

The corresponding `tsconfig.json` would look like:

```json
```json tsconfig
{
"compilerOptions": {
"baseUrl": ".",
Expand Down Expand Up @@ -324,7 +324,7 @@ To specify this relationship to the compiler, use`"rootDirs"`.
`"rootDirs"` specify a list of _roots_ whose contents are expected to merge at run-time.
So following our example, the `tsconfig.json` file should look like:

```json
```json tsconfig
{
"compilerOptions": {
"rootDirs": ["src/views", "generated/templates/views"]
Expand All @@ -346,7 +346,7 @@ export default ["您好吗", "很高兴认识你"];

By leveraging `rootDirs` we can inform the compiler of this mapping and thereby allow it to safely resolve `./#{locale}/messages`, even though the directory will never exist. For example, with the following `tsconfig.json`:

```json
```json tsconfig
{
"compilerOptions": {
"rootDirs": ["src/zh", "src/de", "src/#{locale}"]
Expand Down
44 changes: 21 additions & 23 deletions packages/documentation/copy/en/release-notes/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ By default, editors powered by TypeScript's language server do this by walking u

One case where this slightly fell over is when a `tsconfig.json` simply existed to reference other `tsconfig.json` files.

```json5
```json tsconfig
// tsconfig.json
{
files: [],
Expand Down Expand Up @@ -888,7 +888,7 @@ To prevent this, TypeScript 3.8 waits slightly before installing directory watch

Because every project might work better under different strategies, and this new approach might not work well for your workflows, TypeScript 3.8 introduces a new `watchOptions` field in `tsconfig.json` and `jsconfig.json` which allows users to tell the compiler/language service which watching strategies should be used to keep track of files and directories.

```json5
```json tsconfig
{
// Some typical compiler options
compilerOptions: {
Expand Down Expand Up @@ -2342,7 +2342,7 @@ To learn more, [check out the original pull request on GitHub](https://github.co
TypeScript 3.4 introduces a new flag called `--incremental` which tells TypeScript to save information about the project graph from the last compilation.
The next time TypeScript is invoked with `--incremental`, it will use that information to detect the least costly way to type-check and emit changes to your project.
```json5
```json tsconfig
// tsconfig.json
{
compilerOptions: {
Expand All @@ -2360,7 +2360,7 @@ But if it does, `tsc` will try to use that file to incrementally type-check and
These `.tsbuildinfo` files can be safely deleted and don't have any impact on our code at runtime - they're purely used to make compilations faster.
We can also name them anything that we want, and place them anywhere we want using the `--tsBuildInfoFile` flag.
```json5
```json tsconfig
// front-end.tsconfig.json
{
compilerOptions: {
Expand Down Expand Up @@ -3056,7 +3056,7 @@ function unwrap<T>(result: Result<T>) {
TypeScript 3.2 now resolves `tsconfig.json`s from `node_modules`. When using a bare path for the `"extends"` field in `tsconfig.json`, TypeScript will dive into `node_modules` packages for us.
```json5
```json tsconfig
{
"extends": "@my-team/tsconfig-base",
"include": ["./**/*"]
Expand Down Expand Up @@ -3173,7 +3173,7 @@ TypeScript introduces a new feature called `typesVersions` to help accomodate th
When using Node module resolution in TypeScript 3.1, when TypeScript cracks open a `package.json` file to figure out which files it needs to read, it first looks at a new field called `typesVersions`.
A `package.json` with a `typesVersions` field might look like this:
```json
```json tsconfig
{
"name": "package-name",
"version": "1.0",
Expand Down Expand Up @@ -3202,7 +3202,7 @@ The way that TypeScript decides on whether a version of the compiler & language
`typesVersions` can support multiple fields where each field name is specified by the range to match on.
```json
```json tsconfig
{
"name": "package-name",
"version": "1.0",
Expand All @@ -3217,7 +3217,7 @@ The way that TypeScript decides on whether a version of the compiler & language
Since ranges have the potential to overlap, determining which redirect applies is order-specific.
That means in the above example, even though both the `>=3.2` and the `>=3.1` matchers support TypeScript 3.2 and above, reversing the order could have different behavior, so the above sample would not be equivalent to the following.
```json5
```json tsconfig
{
name: "package-name",
version: "1.0",
Expand Down Expand Up @@ -3880,9 +3880,7 @@ settings.debug === true; // OK
settings.dry === 2; // Error: Operator '===' cannot be applied boolean and number
```
```ts
// tsconfig.json
```json tsconfig
{
"compilerOptions": {
"module": "commonjs",
Expand Down Expand Up @@ -5807,7 +5805,7 @@ TypeScript 2.1 brings the capability to ES3 and ES5 run-times, meaning you'll be

##### tsconfig.json

```json
```json tsconfig
{
"compilerOptions": {
"lib": ["dom", "es2015.promise", "es5"]
Expand Down Expand Up @@ -6093,7 +6091,7 @@ TypeScript 2.1 supports inheriting configuration using `extends`, where:

`configs/base.json`:

```json
```json tsconfig
{
"compilerOptions": {
"noImplicitAny": true,
Expand All @@ -6104,7 +6102,7 @@ TypeScript 2.1 supports inheriting configuration using `extends`, where:

`tsconfig.json`:

```json
```json tsconfig
{
"extends": "./configs/base",
"files": ["main.ts", "supplemental.ts"]
Expand All @@ -6113,7 +6111,7 @@ TypeScript 2.1 supports inheriting configuration using `extends`, where:

`tsconfig.nostrictnull.json`:

```json
```json tsconfig
{
"extends": "./tsconfig",
"compilerOptions": {
Expand Down Expand Up @@ -6611,7 +6609,7 @@ Glob-like file patterns are supported two properties `"include"` and `"exclude"`
#### Example
```json
```json tsconfig
{
"compilerOptions": {
"module": "commonjs",
Expand Down Expand Up @@ -6656,7 +6654,7 @@ All module imports with non-relative names are assumed to be relative to the `ba
#### Example
```json
```json tsconfig
{
"compilerOptions": {
"baseUrl": "./modules"
Expand All @@ -6681,7 +6679,7 @@ The TypeScript compiler supports the declaration of such mappings using `"paths"
For instance, an import to a module `"jquery"` would be translated at runtime to `"node_modules/jquery/dist/jquery.slim.min.js"`.
```json
```json tsconfig
{
"compilerOptions": {
"baseUrl": "./node_modules",
Expand Down Expand Up @@ -6721,7 +6719,7 @@ At run-time, a view can expect its template to exist next to it, and thus should
`"rootDirs"` specify a list of _roots_ whose contents are expected to merge at run-time.
So following our example, the `tsconfig.json` file should look like:
```json
```json tsconfig
{
"compilerOptions": {
"rootDirs": ["src/views", "generated/templates/views"]
Expand Down Expand Up @@ -6966,7 +6964,7 @@ Here is a list of available API groups:
tsc --target es5 --lib es5,es2015.promise
```
```json
```json tsconfig
"compilerOptions": {
"lib": ["es5", "es2015.promise"]
}
Expand Down Expand Up @@ -7704,7 +7702,7 @@ TypeScript 1.7 adds `ES6` to the list of options available for the `--module` fl
##### Example
```json
```json tsconfig
{
"compilerOptions": {
"module": "amd",
Expand Down Expand Up @@ -8290,7 +8288,7 @@ if (isCat(x)) {
A tsconfig.json file that doesn't specify a files property (and therefore implicitly references all \*.ts files in all subdirectories) can now contain an exclude property that specifies a list of files and/or directories to exclude from the compilation. The exclude property must be an array of strings that each specify a file or folder name relative to the location of the tsconfig.json file. For example:
```json
```json tsconfig
{
"compilerOptions": {
"out": "test.js"
Expand Down Expand Up @@ -8639,7 +8637,7 @@ Adding a `tsconfig.json` file in a directory indicates that the directory is the
##### Example
```json
```json tsconfig
{
"compilerOptions": {
"module": "commonjs",
Expand Down
10 changes: 5 additions & 5 deletions packages/documentation/copy/en/release-notes/TypeScript 1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ function makeNode(name: string, initialNeighbor: Node): Node {
return {
name: name,
neighbors: {
[initialNeighbor.name]: initialNeighbor
}
[initialNeighbor.name]: initialNeighbor,
},
};
}
```
Expand Down Expand Up @@ -308,7 +308,7 @@ will be emitted as

```js
function oddRawStrings(strs, n1, n2) {
return strs.raw.filter(function(raw, index) {
return strs.raw.filter(function (raw, index) {
return index % 2 === 1;
});
}
Expand All @@ -334,7 +334,7 @@ moduleA.callStuff();
Generated JS code:

```js
define(["require", "exports", "legacy/moduleA"], function(
define(["require", "exports", "legacy/moduleA"], function (
require,
exports,
moduleA
Expand All @@ -353,7 +353,7 @@ The tsconfig.json file specifies the root files and the compiler options require

##### Example

```json
```json tsconfig
{
"compilerOptions": {
"module": "commonjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ A tsconfig.json file that doesn't specify a files property (and therefore implic
The exclude property must be an array of strings that each specify a file or folder name relative to the location of the tsconfig.json file.
For example:

```json
```json tsconfig
{
"compilerOptions": {
"out": "test.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function printDelayed(elements: string[]) {
}

async function delay(milliseconds: number) {
return new Promise<void>(resolve => {
return new Promise<void>((resolve) => {
setTimeout(resolve, milliseconds);
});
}
Expand All @@ -47,7 +47,7 @@ This provides more flexibility to target exactly the features you want in specif

##### Example

```json
```json tsconfig
{
"compilerOptions": {
"module": "amd",
Expand Down Expand Up @@ -96,10 +96,7 @@ A user could express `2 * 5 + 1` as
```ts
import calc from "./BasicCalculator";

let v = new calc(2)
.multiply(5)
.add(1)
.currentValue();
let v = new calc(2).multiply(5).add(1).currentValue();
```

This often opens up very elegant ways of writing code; however, there was a problem for classes that wanted to extend from `BasicCalculator`.
Expand Down
Loading

0 comments on commit 0bbfda2

Please sign in to comment.