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: API-Breaking-Changes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ See https://github.com/Microsoft/TypeScript/pull/15594 for more details.
39
39
40
40
# TypeScript 1.9
41
41
42
-
-[`LanguageService.getSourceFile`is removed](https://github.com/Microsoft/TypeScript/pull/7584); `LanguageService.getProgram().getSourceFile` should be used instead.
42
+
-[`LanguageService.getSourceFile`has been removed](https://github.com/Microsoft/TypeScript/pull/7584); `LanguageService.getProgram().getSourceFile` should be used instead.
Copy file name to clipboardExpand all lines: Breaking-Changes.md
+218Lines changed: 218 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,230 @@ These changes list where implementation differs between versions as the spec and
2
2
3
3
> For breaking changes to the compiler/services API, please check the [[API Breaking Changes]] page.
4
4
5
+
# TypeScript 3.1
6
+
7
+
## Some vendor-specific types are removed from `lib.d.ts`
8
+
9
+
TypeScript's built-in `.d.ts` library (`lib.d.ts` and family) is now partially generated from Web IDL files from the DOM specification. As a result some vendor-specific types have been removed.
10
+
11
+
<details><summary>Click here to the full list of removed types:</summary><p>
## Narrowing functions now intersects `{}`, `Object`, and unconstrained generic type parameters.
191
+
192
+
The following code will now complain about `x` no longer being callable:
193
+
194
+
```ts
195
+
function foo<T>(x:T| (() =>string)) {
196
+
if (typeofx==="function") {
197
+
x();
198
+
// ~~~
199
+
// Cannot invoke an expression whose type lacks a call signature. Type '(() => string) | (T & Function)' has no compatible call signatures.
200
+
}
201
+
}
202
+
```
203
+
204
+
This is because, unlike previously where `T` would be narrowed away, it is now *expanded* into `T & Function`. However, because this type has no call signatures declared, the type system won't find any common call signature between `T & Function` and `() => string`.
205
+
206
+
Instead, consider using a more specific type than `{}` or `Object`, and consider adding additional constraints to what you expect `T` might be.
207
+
5
208
# TypeScript 3.0
6
209
7
210
## The `unknown` keyword is reserved
8
211
9
212
`unknown` is now a reserved type name, as it is now a built-in type. Depending on your intended use of `unknown`, you may want to remove the declaration entirely (favoring the newly introduced `unknown` type), or rename it to something else.
10
213
214
+
## Intersecting with `null`/`undefined` reduces to `null`/`undefined` outside of `strictNullChecks`
215
+
216
+
In the following example, `A` has the type `null` and `B` has the type `undefined` when `strictNullChecks` is turned off:
217
+
218
+
```ts
219
+
typeA= { a:number } &null; // null
220
+
typeB= { a:number } &undefined; // undefined
221
+
```
222
+
223
+
This is because TypeScript 3.0 is better at reducing subtypes and supertypes in intersection and union types respectively; however, because `null` and `undefined` are both considered subtypes of every other type when `strictNullChecks` is off, an intersection with some object type and either will always reduce to `null` or `undefined`.
224
+
225
+
### Recommendation
226
+
227
+
If you were relying on `null` and `undefined` to be ["identity" elements](https://en.wikipedia.org/wiki/Identity_element) under intersections, you should look for a way to use `unknown` instead of `null` or `undefined` wherever they appeared
228
+
11
229
# TypeScript 2.9
12
230
13
231
## `keyof` now includes `string`, `number` and `symbol` keys
0 commit comments