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
tsTryfunctioncompact (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!
tsTryfunctioncompact (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
tsTryconstarr = [1, 2];functionsum (...arr : number[]) {returnarr .s }
tsTryconstarr = [1, 2];functionsum (...arr : number[]) {returnarr .s }
twoslash error
tsTryconsta = "123";Cannot assign to 'a' because it is a constant.2588Cannot assign to 'a' because it is a constant.= 132; a
tsTryconsta = "123";Cannot assign to 'a' because it is a constant.2588Cannot assign to 'a' because it is a constant.= 132; a
twoslash filecut
tsTryimport {helloWorld } from "./a";console .log (helloWorld );
tsTryimport {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
tsTryconsole .log ("Hello world");console .warn ("Ola Mundo");console .error ("Neih hou");
tsTryconsole .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
tsTryfunctioncreateLabel <T extends number | string>(idOrName :T ):NameOrId <T > {throw "unimplemented";}leta =createLabel ("typescript");letb =createLabel (2.8);letc =createLabel (Math .random () ? "hello" : 42);
tsTryfunctioncreateLabel <T extends number | string>(idOrName :T ):NameOrId <T > {throw "unimplemented";}leta =createLabel ("typescript");letb =createLabel (2.8);letc =createLabel (Math .random () ? "hello" : 42);