Skip to content

Commit fc4defa

Browse files
committed
delete twoslash
1 parent 063153c commit fc4defa

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: pages/release-notes/typescript-4.0.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ When generic spreads are instantiated (or, replaced with a real type) in these t
7373

7474
For example, that means we can type function like `tail`, without our "death by a thousand overloads" issue.
7575

76-
```ts twoslash
76+
```ts
7777
function tail<T extends any[]>(arr: readonly [any, ...T]) {
7878
const [_ignored, ...rest] = arr;
7979
return rest;
@@ -91,7 +91,7 @@ const r2 = tail([...myTuple, ...myArray] as const);
9191

9292
The second change is that rest elements can occur anywhere in a tuple - not just at the end!
9393

94-
```ts twoslash
94+
```ts
9595
type Strings = [string, string];
9696
type Numbers = [number, number];
9797

@@ -109,7 +109,7 @@ But with TypeScript 4.0, this restriction is relaxed.
109109

110110
Note that in cases when we spread in a type without a known length, the resulting type becomes unbounded as well, and all the following elements factor into the resulting rest element type.
111111

112-
```ts twoslash
112+
```ts
113113
type Strings = [string, string];
114114
type Numbers = number[];
115115

@@ -119,7 +119,7 @@ type Unbounded = [...Strings, ...Numbers, boolean];
119119

120120
By combining both of these behaviors together, we can write a single well-typed signature for `concat`:
121121

122-
```ts twoslash
122+
```ts
123123
type Arr = readonly any[];
124124

125125
function concat<T extends Arr, U extends Arr>(arr1: T, arr2: U): [...T, ...U] {
@@ -142,7 +142,7 @@ function partialCall(f, ...headArgs) {
142142

143143
TypeScript 4.0 improves the inference process for rest parameters and rest tuple elements so that we can type this and have it "just work".
144144

145-
```ts twoslash
145+
```ts
146146
type Arr = readonly unknown[];
147147

148148
function partialCall<T extends Arr, U extends Arr, R>(
@@ -155,7 +155,7 @@ function partialCall<T extends Arr, U extends Arr, R>(
155155

156156
In this case, `partialCall` understands which parameters it can and can't initially take, and returns functions that appropriately accept and reject anything left over.
157157

158-
```ts twoslash
158+
```ts
159159
// @errors: 2345 2554 2554 2345
160160
type Arr = readonly unknown[];
161161

@@ -213,7 +213,7 @@ function foo(arg0: string, arg1: number): void {
213213

214214
...for any caller of `foo`.
215215

216-
```ts twoslash
216+
```ts
217217
// @errors: 2554
218218
function foo(arg0: string, arg1: number): void {
219219
// ...
@@ -244,15 +244,15 @@ type Foo = [first: number, second?: string, ...rest: any[]];
244244
There are a few rules when using labeled tuples.
245245
For one, when labeling a tuple element, all other elements in the tuple must also be labeled.
246246

247-
```ts twoslash
247+
```ts
248248
// @errors: 5084
249249
type Bar = [first: string, number];
250250
```
251251

252252
It's worth noting - labels don't require us to name our variables differently when destructuring.
253253
They're purely there for documentation and tooling.
254254

255-
```ts twoslash
255+
```ts
256256
function foo(x: [first: string, second: number]) {
257257
// ...
258258

@@ -277,7 +277,7 @@ To learn more, check out [the pull request](https://github.com/microsoft/TypeScr
277277
TypeScript 4.0 can now use control flow analysis to determine the types of properties in classes when `noImplicitAny` is enabled.
278278

279279
<!--prettier-ignore -->
280-
```ts twoslash
280+
```ts
281281
class Square {
282282
// Previously both of these were any
283283
area;
@@ -294,7 +294,7 @@ class Square {
294294
In cases where not all paths of a constructor assign to an instance member, the property is considered to potentially be `undefined`.
295295

296296
<!--prettier-ignore -->
297-
```ts twoslash
297+
```ts
298298
// @errors: 2532
299299
class Square {
300300
sideLength;
@@ -314,7 +314,7 @@ class Square {
314314

315315
In cases where you know better (e.g. you have an `initialize` method of some sort), you'll still need an explicit type annotation along with a definite assignment assertion (`!`) if you're in `strictPropertyInitialization`.
316316

317-
```ts twoslash
317+
```ts
318318
class Square {
319319
// definite assignment assertion
320320
// v
@@ -421,7 +421,7 @@ if (!obj.prop) {
421421

422422
[Try running the following example](https://www.typescriptlang.org/play?ts=Nightly#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment.
423423

424-
```ts twoslash
424+
```ts
425425
const obj = {
426426
get prop() {
427427
console.log("getter has run");
@@ -456,7 +456,7 @@ You can also [check out TC39's proposal repository for this feature](https://git
456456
Since the beginning days of TypeScript, `catch` clause variables have always been typed as `any`.
457457
This meant that TypeScript allowed you to do anything you wanted with them.
458458

459-
```ts twoslash
459+
```ts
460460
try {
461461
// Do some work
462462
} catch (x) {
@@ -475,7 +475,7 @@ That's why TypeScript 4.0 now lets you specify the type of `catch` clause variab
475475
`unknown` is safer than `any` because it reminds us that we need to perform some sorts of type-checks before operating on our values.
476476

477477
<!--prettier-ignore -->
478-
```ts twoslash
478+
```ts
479479
// @errors: 2571
480480
try {
481481
// ...
@@ -520,7 +520,7 @@ As an example, the following `tsconfig.json` file tells TypeScript to transform
520520
In cases where you need to have a different JSX factory on a per-file basis<!-- (maybe you like to ship React, Preact, and Inferno to give a blazing fast experience) -->, you can take advantage of the new `/** @jsxFrag */` pragma comment.
521521
For example, the following...
522522

523-
```tsx twoslash
523+
```tsx
524524
// @noErrors
525525
// Note: these pragma comments need to be written
526526
// with a JSDoc-style multiline syntax to take effect.
@@ -539,7 +539,7 @@ export const Header = (
539539

540540
...will get transformed to this output JavaScript...
541541

542-
```tsx twoslash
542+
```tsx
543543
// @noErrors
544544
// @showEmit
545545
// Note: these pragma comments need to be written
@@ -682,7 +682,7 @@ MDN recommends moving to [`self.origin`](https://developer.mozilla.org/en-US/doc
682682

683683
Previously, it was only an error for properties to override accessors, or accessors to override properties, when using `useDefineForClassFields`; however, TypeScript now always issues an error when declaring a property in a derived class that would override a getter or setter in the base class.
684684

685-
```ts twoslash
685+
```ts
686686
// @errors: 1049 2610
687687
class Base {
688688
get foo() {
@@ -698,7 +698,7 @@ class Derived extends Base {
698698
}
699699
```
700700

701-
```ts twoslash
701+
```ts
702702
// @errors: 2611
703703
class Base {
704704
prop = 10;
@@ -718,7 +718,7 @@ See more details on [the implementing pull request](https://github.com/microsoft
718718
When using the `delete` operator in `strictNullChecks`, the operand must now be `any`, `unknown`, `never`, or be optional (in that it contains `undefined` in the type).
719719
Otherwise, use of the `delete` operator is an error.
720720

721-
```ts twoslash
721+
```ts
722722
// @errors: 2790
723723
interface Thing {
724724
prop: string;

0 commit comments

Comments
 (0)