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
Copy file name to clipboardExpand all lines: FAQ.md
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,7 @@ Because of this omission, TypeScript must be more permissive when asked whether
187
187
188
188
To understand why, consider two questions: Is `Dog[]` a subtype of `Animal[]` ? *Should* `Dog[]` be a subtype of `Animal[]` in TypeScript?
189
189
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.
191
191
What if the answer was "no" ?
192
192
193
193
```ts
@@ -240,7 +240,7 @@ so we have to take a correctness trade-off for the specific case of function arg
240
240
>```
241
241
242
242
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.
244
244
245
245
Second, let's consider another case:
246
246
```ts
@@ -608,7 +608,7 @@ function createLog(source:string, message?:string): number {
608
608
}
609
609
```
610
610
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.
612
612
613
613
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:
614
614
@@ -937,15 +937,16 @@ One can manually copy methods from the prototype onto the instance itself (i.e.
937
937
938
938
TypeScript uses a structural type system.
939
939
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.
942
942
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.
944
944
The type will have unexpected compatibility (as shown here) and will also fail to have proper generic type inference in function calls.
945
945
946
946
### Why doesn't type inference work on this interface: `interfaceFoo<T> { }` ?
947
947
948
948
> I wrote some code like this:
949
+
>
949
950
> ```ts
950
951
>interfaceNamed<T> {
951
952
> name:string;
@@ -963,7 +964,7 @@ The type will have unexpected compatibility (as shown here) and will also fail t
963
964
>```
964
965
965
966
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.
967
968
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.
968
969
Because there are no members which use `T`, there is nothing to infer from, so we return `{}`.
969
970
@@ -1360,9 +1361,9 @@ To ensure the output does not change with adding new files specify `--rootDir` o
1360
1361
1361
1362
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”`.
1362
1363
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*nsfrom “mod”`. 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*nsfrom “mod”`. 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.
1364
1365
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.
However, ifyouhavesetthe`allowJs`compileroptionto`true`anddidn'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, ifyouhavesetthe`allowJs`compileroptionto`true`anddidn'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.
Copy file name to clipboardExpand all lines: Standalone-Server-(tsserver).md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,15 +55,18 @@ Each command is associated with a request and a response interface. For instance
55
55
56
56
[TypeScript-Sublime-Plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) is a Sublime text plugin written in Python that uses `tsserver`.
57
57
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
61
59
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`.
62
61
63
62
## Tide
64
63
65
64
[Tide](https://github.com/ananthakumaran/tide) is an elisp implementation for emacs plugin using `tsserver`
66
65
66
+
## Neovim
67
+
68
+
[nvim-typescript](https://github.com/mhartington/nvim-typescript) is a neovim plugin using `tsserver`
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.
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
+
```
82
92
83
-
# Visual Studio 2013/2015
93
+
# Visual Studio
84
94
85
95
[Visual Studio](https://www.visualstudio.com/) comes with TypeScript when installing Microsoft Web Tools.
86
96
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)
88
98
89
99
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)
Copy file name to clipboardExpand all lines: Using-the-Language-Service-API.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ For instance, a call to `getSyntacticDiagnostics` will only need the file in que
19
19
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.
20
20
21
21
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.
23
23
24
24
## Language Service Host
25
25
@@ -42,7 +42,7 @@ Incremental parsing asks the second question to ensure it only re-parses changed
42
42
43
43
## Reference resolution in the language service
44
44
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.
46
46
47
47
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.
0 commit comments