Table of contents
Open Table of contents
twoslash Tests
tsTry
// ts twoslashconsole .log (str );
tsTry
// ts twoslashconsole .log (str );
ts
// tsconst str = "hello world";console.log(str);
ts
// tsconst str = "hello world";console.log(str);
twoslash annotation
tsTry
functioncompact (arr ) {if (Cannot find name 'orr'.2304Cannot find name 'orr'.. orr length > 10) {returnarr .trim (0, 10);}returnarr ;}
Discovered a typo, the param is arr, not orr!
tsTry
functioncompact (arr ) {if (Cannot find name 'orr'.2304Cannot find name 'orr'.. orr length > 10) {returnarr .trim (0, 10);}returnarr ;}
Discovered a typo, the param is arr, not orr!
twoslash completions
tsTry
constarr = [1, 2];functionsum (...arr : number[]) {returnarr .s }
tsTry
constarr = [1, 2];functionsum (...arr : number[]) {returnarr .s }
twoslash error
tsTry
consta = "123";Cannot assign to 'a' because it is a constant.2588Cannot assign to 'a' because it is a constant.= 132; a
tsTry
consta = "123";Cannot assign to 'a' because it is a constant.2588Cannot assign to 'a' because it is a constant.= 132; a
twoslash filecut
tsTry
import {helloWorld } from "./a";console .log (helloWorld );
tsTry
import {helloWorld } from "./a";console .log (helloWorld );
twoslash json
tsTry
// @filename: app.json{ "version": "23.2.3" }// @filename: index.tsimportappSettings from "./app.json"appSettings .version
tsTry
// @filename: app.json{ "version": "23.2.3" }// @filename: index.tsimportappSettings from "./app.json"appSettings .version
twoslash log
tsTry
console .log ("Hello world");console .warn ("Ola Mundo");console .error ("Neih hou");
tsTry
console .log ("Hello world");console .warn ("Ola Mundo");console .error ("Neih hou");
twoslash twofiles
tsTry
// @filename: node_modules/@types/mylib/index.d.tsexport functiondoit (): string;// @filename: index.tsimport {doit } from "mylib";console .log (doit );
tsTry
// @filename: node_modules/@types/mylib/index.d.tsexport functiondoit (): string;// @filename: index.tsimport {doit } from "mylib";console .log (doit );
twoslash
tsTry
functioncreateLabel <T extends number | string>(idOrName :T ):NameOrId <T > {throw "unimplemented";}leta =createLabel ("typescript");letb =createLabel (2.8);letc =createLabel (Math .random () ? "hello" : 42);
tsTry
functioncreateLabel <T extends number | string>(idOrName :T ):NameOrId <T > {throw "unimplemented";}leta =createLabel ("typescript");letb =createLabel (2.8);letc =createLabel (Math .random () ? "hello" : 42);