Skip to content

Commit d241ce3

Browse files
2 parents 09d1dc9 + 9288981 commit d241ce3

File tree

6 files changed

+68
-54
lines changed

6 files changed

+68
-54
lines changed

FAQ.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Because of this omission, TypeScript must be more permissive when asked whether
187187
188188
To understand why, consider two questions: Is `Dog[]` a subtype of `Animal[]` ? *Should* `Dog[]` be a subtype of `Animal[]` in TypeScript?
189189
190-
The second question (*should* `Dog[]` be a subtype of `Animal[]`?) is an easier to analyze.
190+
The second question (*should* `Dog[]` be a subtype of `Animal[]`?) is easier to analyze.
191191
What if the answer was "no" ?
192192
193193
```ts
@@ -240,7 +240,7 @@ so we have to take a correctness trade-off for the specific case of function arg
240240
> ```
241241
242242
This is the expected and desired behavior.
243-
First, refer to the "substitutability" primer at the top of the FAQ -- `handler` is a valid argument for `callback` because it can safely ignored extra parameters.
243+
First, refer to the "substitutability" primer at the top of the FAQ -- `handler` is a valid argument for `callback` because it can safely ignore extra parameters.
244244
245245
Second, let's consider another case:
246246
```ts
@@ -608,7 +608,7 @@ function createLog(source:string, message?:string): number {
608608
}
609609
```
610610
611-
The rationale here is that since JavaScript does not have function overloading, you will be doing parameter checking in your function, and this your function implementation might be more permissive that what you would want your users to call you through.
611+
The rationale here is that since JavaScript does not have function overloading, you will be doing parameter checking in your function, and this your function implementation might be more permissive than what you would want your users to call you through.
612612
613613
For instance you can require your users to call you using matching pairs of arguments, and implement this correctly without having to allow mixed argument types:
614614
@@ -937,15 +937,16 @@ One can manually copy methods from the prototype onto the instance itself (i.e.
937937
938938
TypeScript uses a structural type system.
939939
When determining compatibility between `Something<number>` and `Something<string>`, we examine each *member* of each type.
940-
If each member of the types are compatible, then the type are compatible as well.
941-
Because `Something<T>` doesn't *use* `T` in any member, it doesn't matter what type `T` is.
940+
If all of the members are compatible, then the types themselves are compatible.
941+
But because `Something<T>` doesn't *use* `T` in any member, it doesn't matter what type `T` is - it has no bearing on whether the types are compatible.
942942
943-
In general, you should *never* have a type parameter which is unused.
943+
In general, you should *never* have type parameters which are unused.
944944
The type will have unexpected compatibility (as shown here) and will also fail to have proper generic type inference in function calls.
945945
946946
### Why doesn't type inference work on this interface: `interface Foo<T> { }` ?
947947
948948
> I wrote some code like this:
949+
>
949950
> ```ts
950951
> interface Named<T> {
951952
> name: string;
@@ -963,7 +964,7 @@ The type will have unexpected compatibility (as shown here) and will also fail t
963964
> ```
964965
965966
TypeScript uses a structural type system.
966-
This structuralness also applies during generic type inference.
967+
This structural-ness also applies during generic type inference.
967968
When inferring the type of `T` in the function call, we try to find *members* of type `T` on the `x` argument to figure out what `T` should be.
968969
Because there are no members which use `T`, there is nothing to infer from, so we return `{}`.
969970
@@ -1360,9 +1361,9 @@ To ensure the output does not change with adding new files specify `--rootDir` o
13601361
13611362
If you want to exclude some of the files use `exclude`, if you would rather specify all the files instead of letting the compiler look them up, use `files`.
13621363
1363-
That was `tsconfig.json` automatic inclusion. There is a different issue, which is module resolution. By module resolution, I mean the compiler trying to understand what `ns` means in an import statement like: `import * ns frommod`. To do so, the compiler needs the definition of a module, this could be a .ts file for your own code, or a .d.ts for an imported definition files. if the file was found, it will be included regardless if it was excluded in the previous steps.
1364+
That was `tsconfig.json` automatic inclusion. There is a different issue, which is module resolution. By module resolution, I mean the compiler trying to understand what `ns` means in an import statement like: `import * ns frommod`. To do so, the compiler needs the definition of a module, this could be a .ts file for your own code, or a .d.ts for an imported definition file. if the file was found, it will be included regardless if it was excluded in the previous steps.
13641365
1365-
So to exclude a file from the compilation, you need to exclude and all **all** files that has an `import` or `/// <reference path="..." />` directives to it.
1366+
So to exclude a file from the compilation, you need to exclude and all **all** files that have an `import` or `/// <reference path="..." />` directives to them.
13661367
13671368
Use `tsc --listFiles` to list what files are included in your compilation, and `tsc --traceResolution` to see why they were included.
13681369
@@ -1374,7 +1375,7 @@ There is no way now to indicate an `“include”` to a file outside the current
13741375
13751376
For a TypeScript file, the TypeScript compiler by default emits the generated JavaScript files in the same directory with the same base file name.
13761377
Because the TypeScript files and emitted JavaScript files always have different file extensions, it is safe to do so.
1377-
However, if you have set the `allowJs` compiler option to `true` and didn't set any emit output options (`outFile` and `outDir`), the compiler will try to emit JavaScript source files by the same rule, which will result in the emitted JavaScript file having the same file name with the source file. To avoid accidently overwriting your source file, the compiler will issue this warning and skip writing the output files.
1378+
However, if you have set the `allowJs` compiler option to `true` and didn't set any emit output options (`outFile` and `outDir`), the compiler will try to emit JavaScript source files by the same rule, which will result in the emitted JavaScript file having the same file name with the source file. To avoid accidently overwriting your source file, the compiler will issue this warning and skip writing the output files.
13781379
13791380
There are multiple ways to solve this issue, though all of them involve configuring compiler options, therefore it is recommended that you have a `tsconfig.json` file in the project root to enable this.
13801381
If you don't want JavaScript files included in your project at all, simply set the `allowJs` option to `false`;
@@ -1386,7 +1387,7 @@ If you just want to include the JavaScript files for editing and don't need to c
13861387
### Why some comments are not preserved in emitted JavaScript even when `--removeComments` is not specified?
13871388
13881389
TypeScript compiler uses a position of a node in the abstract syntax tree to retrieve its comments during emit.
1389-
Because, the compiler does not store all tokens into the tree, some comments may be missed in an output JavaScript file.
1390+
Because the compiler does not store all tokens into the tree, some comments may be missed in an output JavaScript file.
13901391
For example, we do not store following tokens into the tree `,`, `{`, `}`, `(`, `)`.
13911392
Therefore, trailing comments or leading comments of such token cannot be retrieved during emit.
13921393
At the moment, there is not an easy method to preserve such comments without storing those tokens.
@@ -1401,8 +1402,8 @@ Some cases where TypeScript compiler will not be able to preserve your comments:
14011402
</div>
14021403
14031404
var x = {
1404-
prop1: 1, // won't get emit because we can't retrieve this comment
1405-
prop2: 2 // will be emit
1405+
prop1: 1, // won't get emitted because we can't retrieve this comment
1406+
prop2: 2 // will be emitted
14061407
}
14071408
14081409
function foo() /* this comment can't be preserved */ { }
@@ -1412,7 +1413,7 @@ function foo() /* this comment can't be preserved */ { }
14121413
### Why Copyright comments are removed when `--removeComments` is true?
14131414
14141415
TypeScript compiler will preserve copyright comment regardless of `--removeComments`.
1415-
For a comment to be considered a copyright comment, it must have following characteristics:
1416+
For a comment to be considered a copyright comment, it must have the following characteristics:
14161417
14171418
- a top-of-file comment following by empty line, separating it from the first statement.
14181419
- begin with `/*!`
@@ -1505,7 +1506,7 @@ function foo /*trailing comments of the function name, "foo", AST node*/ () {
15051506
> I don't think this suggestion should have been closed! What can I do next?
15061507
15071508
To date, we've received over 1,000 suggestions on the TypeScript GitHub repo.
1508-
We do our best to read, understand, prioritize, formalize, and implement these suggestions.
1509+
We do our best to read, understand, prioritize, formalize and implement these suggestions.
15091510
User feedback has been critical in shaping the success of the project.
15101511
That said, sometimes we'll make decisions that you don't agree with, and sometimes we'll make the wrong call.
15111512
What should you do if you think we should reconsider something?

JSDoc-support-in-JavaScript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ import types can also be used in type alias declarations:
156156

157157
```js
158158
/**
159-
* @typedef Pet { import("./a").Pet }
159+
* @typedef { import("./a").Pet } Pet
160160
*/
161161

162162
/**

Standalone-Server-(tsserver).md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ Each command is associated with a request and a response interface. For instance
5555

5656
[TypeScript-Sublime-Plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) is a Sublime text plugin written in Python that uses `tsserver`.
5757

58-
## VS Code
59-
60-
[VS Code](https://code.visualstudio.com/)'s [TypeScript support](https://github.com/Microsoft/vscode/tree/master/extensions/typescript) is implemented in TypeScript using `tsserver`.
58+
## Visual Studio Code
6159

60+
[S Code](https://code.visualstudio.com/)'s [TypeScript support](https://github.com/Microsoft/vscode/tree/master/extensions/typescript) is implemented in TypeScript using `tsserver`.
6261

6362
## Tide
6463

6564
[Tide](https://github.com/ananthakumaran/tide) is an elisp implementation for emacs plugin using `tsserver`
6665

66+
## Neovim
67+
68+
[nvim-typescript](https://github.com/mhartington/nvim-typescript) is a neovim plugin using `tsserver`
69+
6770
# Advanced topics
6871

6972
## Logging

TypeScript-Editor-Support.md

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Quick List
22

3-
* [alm.tools](#alm)
4-
* [Atom](#atom)
5-
* [CATS](#cats)
6-
* [Eclipse](#eclipse)
7-
* [Emacs](#emacs)
8-
* [NeoVim](#neovim)
9-
* [NetBeans](#netbeans)
10-
* [Notepad++](#notepad)
11-
* [Sublime Text](#sublime-text)
12-
* [Vim](#vim)
13-
* [Visual Studio](#visual-studio-20132015)
14-
* [Visual Studio Code](#visual-studio-code)
15-
* [WebStorm](#webstorm)
3+
* [alm.tools](#alm)
4+
* [Atom](#atom)
5+
* [CATS](#cats)
6+
* [Eclipse](#eclipse)
7+
* [Emacs](#emacs)
8+
* [NeoVim](#neovim)
9+
* [NetBeans](#netbeans)
10+
* [Notepad++](#notepad)
11+
* [Sublime Text](#sublime-text)
12+
* [Vim](#vim)
13+
* [Visual Studio](#visual-studio-20132015)
14+
* [Visual Studio Code](#visual-studio-code)
15+
* [WebStorm](#webstorm)
1616

1717
# alm
1818

@@ -67,24 +67,34 @@ The [TypeScript Plugin for Sublime](https://github.com/Microsoft/TypeScript-Subl
6767

6868
* [Quramy/tsuquyomi](https://github.com/Quramy/tsuquyomi)
6969

70-
If you would like to have as-you-type completion, you can install [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) and add the following code into your `.vimrc` to specify what token will trigger the completion. YouCompleteMe will call into its respective TypeScript Plugin for semantic queries.
70+
If you would like to have as-you-type completion, you can install [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) and add the following code into your `.vimrc` to specify what token will trigger the completion. YouCompleteMe will call into its respective TypeScript Plugin for semantic queries.
7171

72-
```vimscript
73-
if !exists("g:ycm_semantic_triggers")
74-
let g:ycm_semantic_triggers = {}
75-
endif
76-
let g:ycm_semantic_triggers['typescript'] = ['.']
77-
```
72+
```vimscript
73+
if !exists("g:ycm_semantic_triggers")
74+
let g:ycm_semantic_triggers = {}
75+
endif
76+
let g:ycm_semantic_triggers['typescript'] = ['.']
77+
```
7878

7979
* [mhartington/nvim-typescript](https://github.com/mhartington/nvim-typescript)
8080

81-
As-you-type deoplete asynchronous completion framework for Vim 8. Needs [Shougo/deoplete.nvim](https://github.com/Shougo/deoplete.nvim) in order to work.
81+
As-you-type deoplete asynchronous completion framework for Vim 8. Needs [Shougo/deoplete.nvim](https://github.com/Shougo/deoplete.nvim) in order to work.
82+
83+
* [ALE](https://github.com/w0rp/ale)
84+
85+
ALE (Asynchronous Lint Engine) supports as-you-type completion for TypeScript out of the box.
86+
87+
```vimscript
88+
" Enable completion where available.
89+
" This setting must be set before ALE is loaded.
90+
let g:ale_completion_enabled = 1
91+
```
8292

83-
# Visual Studio 2013/2015
93+
# Visual Studio
8494

8595
[Visual Studio](https://www.visualstudio.com/) comes with TypeScript when installing Microsoft Web Tools.
8696

87-
TypeScript for Visual Studio 2017 with [version 15.2 or later](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes-v15.2) can be found [here](https://www.microsoft.com/en-us/download/details.aspx?id=55258)
97+
TypeScript for Visual Studio 2019 and Visual Studio 2017 (with [version 15.2 or later](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes-v15.2)) can be found [here](https://marketplace.visualstudio.com/publishers/TypeScriptTeam)
8898

8999
TypeScript for Visual Studio 2015 with [update 3](https://www.visualstudio.com/en-us/news/releasenotes/vs2015-update3-vs) can be found [here](http://www.microsoft.com/en-us/download/details.aspx?id=48593)
90100

Using-the-Compiler-API.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ export function delint(sourceFile: ts.SourceFile) {
108108
case ts.SyntaxKind.ForInStatement:
109109
case ts.SyntaxKind.WhileStatement:
110110
case ts.SyntaxKind.DoStatement:
111-
if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) {
111+
if ((node as ts.IterationStatement).statement.kind !== ts.SyntaxKind.Block) {
112112
report(
113113
node,
114-
"A looping statement's contents should be wrapped in a block body."
114+
'A looping statement\'s contents should be wrapped in a block body.'
115115
);
116116
}
117117
break;
118118

119119
case ts.SyntaxKind.IfStatement:
120-
let ifStatement = <ts.IfStatement>node;
120+
const ifStatement = node as ts.IfStatement;
121121
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
122122
report(
123123
ifStatement.thenStatement,
124-
"An if statement's contents should be wrapped in a block body."
124+
'An if statement\'s contents should be wrapped in a block body.'
125125
);
126126
}
127127
if (
@@ -131,18 +131,18 @@ export function delint(sourceFile: ts.SourceFile) {
131131
) {
132132
report(
133133
ifStatement.elseStatement,
134-
"An else statement's contents should be wrapped in a block body."
134+
'An else statement\'s contents should be wrapped in a block body.'
135135
);
136136
}
137137
break;
138138

139139
case ts.SyntaxKind.BinaryExpression:
140-
let op = (<ts.BinaryExpression>node).operatorToken.kind;
140+
const op = (node as ts.BinaryExpression).operatorToken.kind;
141141
if (
142142
op === ts.SyntaxKind.EqualsEqualsToken ||
143-
op == ts.SyntaxKind.ExclamationEqualsToken
143+
op === ts.SyntaxKind.ExclamationEqualsToken
144144
) {
145-
report(node, "Use '===' and '!=='.");
145+
report(node, 'Use \'===\' and \'!==\'.');
146146
}
147147
break;
148148
}
@@ -151,7 +151,7 @@ export function delint(sourceFile: ts.SourceFile) {
151151
}
152152

153153
function report(node: ts.Node, message: string) {
154-
let { line, character } = sourceFile.getLineAndCharacterOfPosition(
154+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(
155155
node.getStart()
156156
);
157157
console.log(
@@ -163,7 +163,7 @@ export function delint(sourceFile: ts.SourceFile) {
163163
const fileNames = process.argv.slice(2);
164164
fileNames.forEach(fileName => {
165165
// Parse a file
166-
let sourceFile = ts.createSourceFile(
166+
const sourceFile = ts.createSourceFile(
167167
fileName,
168168
readFileSync(fileName).toString(),
169169
ts.ScriptTarget.ES2015,

Using-the-Language-Service-API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For instance, a call to `getSyntacticDiagnostics` will only need the file in que
1919
The language service design decouples different phases of the compiler pipeline that would normally happen in order in one shot during command-line compilation; and it allows the language service host flexibility in ordering these different phases.
2020

2121

22-
For instance, the language service reports diagnostics on a file per file bases, all while making a distinction between syntactic and semantic errors of each file. This ensures that the host can supply an optimal experience by retrieving syntax errors for a given file without having to pay the cost of querying other files, or performing a full semantic check. It also allows the host to skip querying for syntax errors for files that have not changed. Similarly, the language service allows for emitting a single file (`getEmitOutput`) without having to emit or even type check the whole program.
22+
For instance, the language service reports diagnostics on a file per file basis, all while making a distinction between syntactic and semantic errors of each file. This ensures that the host can supply an optimal experience by retrieving syntax errors for a given file without having to pay the cost of querying other files, or performing a full semantic check. It also allows the host to skip querying for syntax errors for files that have not changed. Similarly, the language service allows for emitting a single file (`getEmitOutput`) without having to emit or even type check the whole program.
2323

2424
## Language Service Host
2525

@@ -42,7 +42,7 @@ Incremental parsing asks the second question to ensure it only re-parses changed
4242
4343
## Reference resolution in the language service
4444

45-
There are two means of declaring dependencies in TypeScript: import statements, and triple-slash reference comments (`/// <reference path="..." />`). Reference resolution for a program is the process of walking the dependency graph between files, and generating a sorted list of files compromising the program.
45+
There are two means of declaring dependencies in TypeScript: import statements, and triple-slash reference comments (`/// <reference path="..." />`). Reference resolution for a program is the process of walking the dependency graph between files, and generating a sorted list of files comprising the program.
4646

4747
In the command-line compiler (`tsc`) this happens as part of building the program. A `createProgram` call starts with a set of root files, parses them in order, and walks their dependency declaration (both imports and triple-slash references) resolving references to actual files on disk and then pulling them into the compilation process.
4848

0 commit comments

Comments
 (0)