From 682e7ffb9a01804dd99ca0bbe6d2a5805b0ad445 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 17 Sep 2020 02:18:37 -0400 Subject: [PATCH 1/3] fix: `jsx` is undefined by default, not preserve or react - one gets an error when using JSX without configuring `jsx`: `error TS17004: Cannot use JSX unless the '--jsx' flag is provided.` - TSConfig Reference said default was `react`, which is inaccurate - Compiler Options said default was `preserve`, which is also inaccurate - Add a `undefined` as the default in TSConfig Reference, same as allowUnrechableCode - Remove the default in Compiler Options, same as all the other options without defaults ---- History: Reference: - `preserve` was written as the default in https://github.com/microsoft/TypeScript-Website/commit/eae5cc3ab38ddce1c0e70e36c223cb07bc734199#diff-444415c73770eafd0f9db7d708d74131R5 - But then was written as `react` in the body in https://github.com/microsoft/TypeScript-Website/commit/eae5cc3ab38ddce1c0e70e36c223cb07bc734199#diff-444415c73770eafd0f9db7d708d74131R5 - It was then switched to `react` in https://github.com/microsoft/TypeScript-Website/commit/450ae964411f5180e4c3f7e6e974ccba03eb4e59#diff-a912c6af3a16bf4288093c1264955bc6R120 - And then removed in https://github.com/microsoft/TypeScript-Website/commit/76b7d435fdbec8a4b88ac0b01b88e3fb72a829d1#diff-a912c6af3a16bf4288093c1264955bc6L120 Compiler Options: - `preserve` was written as the default in https://github.com/microsoft/TypeScript-Website/commit/66f17ad4d0fa6b2b9fee791b0b7a729710aeb907#diff-bfc78b96c15b0ee906c1ab6176546dceR41 --- .../documentation/copy/en/project-config/Compiler Options.md | 2 +- packages/tsconfig-reference/scripts/tsconfigRules.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/documentation/copy/en/project-config/Compiler Options.md b/packages/documentation/copy/en/project-config/Compiler Options.md index 8a7a8ef5a573..4b412c7b1827 100644 --- a/packages/documentation/copy/en/project-config/Compiler Options.md +++ b/packages/documentation/copy/en/project-config/Compiler Options.md @@ -65,7 +65,7 @@ Option | Type | Default `--inlineSources` | `boolean` | `false` | Emit the source alongside the sourcemaps within a single file; requires `--inlineSourceMap` or `--sourceMap` to be set. `--init` | | | Initializes a TypeScript project and creates a `tsconfig.json` file. `--isolatedModules` | `boolean` | `false` | Perform additional checks to ensure that separate compilation (such as with [`transpileModule`](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function) or [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)) would be safe. -`--jsx` | `string` | `"preserve"` | Support JSX in `.tsx` files: `"react"`, `"preserve"`, `"react-native"`. See [JSX](docs/handbook/jsx.html). +`--jsx` | `string` | | Support JSX in `.tsx` files: `"react"`, `"preserve"`, `"react-native"`. See [JSX](docs/handbook/jsx.html). `--jsxFactory` | `string` | `"React.createElement"` | Specify the JSX factory function to use when targeting react JSX emit, e.g. `React.createElement` or `h`. `--jsxFragmentFactory` | `string` | `"React.Fragment"` | Specify the JSX fragment factory function to use when targeting react JSX emit, e.g. `Fragment`. `--keyofStringsOnly` | `boolean` | `false` | Resolve `keyof` to string valued property names only (no numbers or symbols). diff --git a/packages/tsconfig-reference/scripts/tsconfigRules.ts b/packages/tsconfig-reference/scripts/tsconfigRules.ts index b2b99b02f76a..20d0c25419b1 100644 --- a/packages/tsconfig-reference/scripts/tsconfigRules.ts +++ b/packages/tsconfig-reference/scripts/tsconfigRules.ts @@ -121,6 +121,7 @@ export const defaultsForOptions = { inlineSourceMap: "false", inlineSources: "false", isolatedModules: "false", + jsx: "undefined", jsxFactory: "`React.createElement`", keyofStringsOnly: "false", listEmittedFiles: "false", @@ -172,7 +173,7 @@ export const defaultsForOptions = { }; export const allowedValues = { - jsx: ["`react` (default)", "`react-native`", "`preserve`"], + jsx: ["`react`", "`react-native`", "`preserve`"], jsxFactory: ["Any identifier or dotted identifier"], lib: ["See main content"], target: [ From 13ba58aed187278a1c9754bff9788c88bf9eaedc Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 18 Sep 2020 11:19:23 -0400 Subject: [PATCH 2/3] Update Compiler Options.md --- .../documentation/copy/en/project-config/Compiler Options.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/documentation/copy/en/project-config/Compiler Options.md b/packages/documentation/copy/en/project-config/Compiler Options.md index 76ac59c9153c..3e204ed4ed01 100644 --- a/packages/documentation/copy/en/project-config/Compiler Options.md +++ b/packages/documentation/copy/en/project-config/Compiler Options.md @@ -65,7 +65,7 @@ Option | Type | Default `--inlineSources` | `boolean` | `false` | Emit the source alongside the sourcemaps within a single file; requires `--inlineSourceMap` or `--sourceMap` to be set. `--init` | | | Initializes a TypeScript project and creates a `tsconfig.json` file. `--isolatedModules` | `boolean` | `false` | Perform additional checks to ensure that separate compilation (such as with [`transpileModule`](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function) or [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)) would be safe. -`--jsx` | `string` | | Support JSX in `.tsx` files: `"react"`, `"preserve"`, `"react-native"`. See [JSX](docs/handbook/jsx.html). +`--jsx` | `string` | | Support JSX in `.tsx` files: `"react"`, `"preserve"`, `"react-native"`. See [JSX](/docs/handbook/jsx.html). `--jsxFactory` | `string` | `"React.createElement"` | Specify the JSX factory function to use when targeting react JSX emit, e.g. `React.createElement` or `h`. `--jsxFragmentFactory` | `string` | `"React.Fragment"` | Specify the JSX fragment factory function to use when targeting react JSX emit, e.g. `Fragment`. `--keyofStringsOnly` | `boolean` | `false` | Resolve `keyof` to string valued property names only (no numbers or symbols). @@ -100,7 +100,7 @@ Option | Type | Default `--preserveSymlinks` | `boolean` | `false` | Do not resolve symlinks to their real path; treat a symlinked file like a real one. `--preserveWatchOutput` | `boolean` | `false` | Keep outdated console output in watch mode instead of clearing the screen `--pretty` | `boolean` | `true` unless piping to another program or redirecting output to a file | Stylize errors and messages using color and context. -`--project`
`-p` | `string` | | Compile a project given a valid configuration file.
The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](/docs/handbook/tsconfig-json.html) documentation for more details. +`--project`
`-p` | `string` | | Compile a project given a valid configuration file.
The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](/docs/handbook/tsconfig-json.html) documentation for more details/ `--reactNamespace` | `string` | `"React"` | DEPRECATED. Use `--jsxFactory` instead.
Specifies the object invoked for `createElement` and `__spread` when targeting `"react"` JSX emit. `--removeComments` | `boolean` | `false` | Remove all comments except copy-right header comments beginning with `/*!` `--resolveJsonModule` | `boolean` | `false` | Include modules imported with `.json` extension. From b8247bb0436f4381b77f87faf0af07d49cca87eb Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 18 Sep 2020 11:19:52 -0400 Subject: [PATCH 3/3] Update Compiler Options.md --- .../documentation/copy/en/project-config/Compiler Options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/project-config/Compiler Options.md b/packages/documentation/copy/en/project-config/Compiler Options.md index 3e204ed4ed01..c906a9cb8685 100644 --- a/packages/documentation/copy/en/project-config/Compiler Options.md +++ b/packages/documentation/copy/en/project-config/Compiler Options.md @@ -100,7 +100,7 @@ Option | Type | Default `--preserveSymlinks` | `boolean` | `false` | Do not resolve symlinks to their real path; treat a symlinked file like a real one. `--preserveWatchOutput` | `boolean` | `false` | Keep outdated console output in watch mode instead of clearing the screen `--pretty` | `boolean` | `true` unless piping to another program or redirecting output to a file | Stylize errors and messages using color and context. -`--project`
`-p` | `string` | | Compile a project given a valid configuration file.
The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](/docs/handbook/tsconfig-json.html) documentation for more details/ +`--project`
`-p` | `string` | | Compile a project given a valid configuration file.
The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](/docs/handbook/tsconfig-json.html) documentation for more details. `--reactNamespace` | `string` | `"React"` | DEPRECATED. Use `--jsxFactory` instead.
Specifies the object invoked for `createElement` and `__spread` when targeting `"react"` JSX emit. `--removeComments` | `boolean` | `false` | Remove all comments except copy-right header comments beginning with `/*!` `--resolveJsonModule` | `boolean` | `false` | Include modules imported with `.json` extension.