- modules
- Exporting a declaration
- Export statements
- Re - exports
- Import a single export from a module
- Default exports
- Default exports of classes and functions
- Default exports can also be just values:
- export = and import = require()
- Code Generation for Modules
- Simple Example
- Optional Module Loading
- Ambient Modules
- Shorthand ambient modules
- Wildcard module declarations
- UMD modules
- Export as close to top-level as possible
- Re -export to extend
- variables
- function
- class
- interfaces
- Simple interface
- Reference to interface
- Optional properties
- Optional properties 2
- Readonly properties
- Readonly vs const
- Call signature
- Index signature
- Index signature 2
- Index signature 3
- Readonly index signature 3
- Class Types
- static and instance sides of classes - fails
- static and instance sides of classes - succeds
- Extending Interfaces 1
- Extending Interfaces 2
- Hybrid Types
- Class with private property
- Interface extending class
- Derived class extending interface
- Derived class
- Class extending interface
- generics
- Identity function with any
- Identity function with type variable
- Type argument
- Length property fails
- Length property succeds 1
- Length property succeds 2
- Generic function
- Call signature object literal type
- Generic interface
- Generic Classes
- Generic Constraints - fails
- Generic Constraints - succeds
- Type Parameters in Generic Constraints
- Class Types in Generics
- Prototype property
- advanced
- Intersection Types
- Union Types - fail at run time
- Union Types - succeds at run time
- Union Types - common members
- Type Guards and Differentiating Types
- User - Defined Type Guards
- Instanceof type guards
- Nullable types
- Type guards and type assertions
- Type Aliases
- Interfaces vs.Type Aliases
- String Literal Types
- Numeric Literal Types
- Enum Member Types
- Exhaustiveness checking
- Polymorphic this types
- Index types
- Mapped types
- Mapped types 2
- Inference from mapped types
- Conditional Types
- Distributive conditional types
- Conditional types combined with mapped types:
- Type inference in conditional types
- Predefined conditional types
Exporting a declaration
1 +2 #3 # Validation.ts4 export5 :interface StringValidator6 :m isAcceptable7 :boolean8 param s9 :string10 #11 # ZipCodeValidator.ts12 export13 const numberRegexp = /^[0-9]+$/14 export15 class ZipCodeValidator16 :implements StringValidator17 m isAcceptable18 param s19 :string20 return s.length === 5 && numberRegexp.test(s)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export interface StringValidator {
isAcceptable(s: string): boolean;
}
//
export const numberRegexp = /^[0-9]+$/;
export class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
Export statements
1 +2 class ZipCodeValidator3 :implements StringValidator4 m isAcceptable5 param s6 :string7 return s.length === 5 && numberRegexp.test(s)8 export9 @ ZipCodeValidator10 export11 @ ZipCodeValidator12 as mainValidator
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
export {ZipCodeValidator};
export {ZipCodeValidator as mainValidator};
Re - exports
1 +2 #3 # ParseIntBasedZipCodeValidator.ts4 export5 class ParseIntBasedZipCodeValidator6 m isAcceptable7 param s8 :string9 return s.length === 5 && parseInt(s).toString() === s10 export11 @ ZipCodeValidator12 as RegExpBasedZipCodeValidator13 from "./ZipCodeValidator"14 #15 # AllValidators.ts16 export *17 from "./StringValidator"18 export *19 from "./LettersOnlyValidator"20 export *21 from "./ZipCodeValidator"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export class ParseIntBasedZipCodeValidator {
isAcceptable(s: string) {
return s.length === 5 && parseInt(s).toString() === s;
}
}
export {ZipCodeValidator as RegExpBasedZipCodeValidator} from "./ZipCodeValidator";
//
export * from "./StringValidator";
export * from "./LettersOnlyValidator";
export * from "./ZipCodeValidator";
Import a single export from a module
1 +2 import3 @ ZipCodeValidator4 from "./ZipCodeValidator"5 let myValidator = new ZipCodeValidator()6 #7 # imports can also be renamed8 import9 @ ZipCodeValidator10 as ZCV11 from "./ZipCodeValidator"12 let myValidator = new ZCV()13 #14 # Import the entire module into a single variable, and use it to access the module exports15 import16 as validator17 from "./ZipCodeValidator"18 let myValidator = new validator.ZipCodeValidator()19 #20 # Import a module for side- effects only21 import "./my-module.js"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
import {ZipCodeValidator} from "./ZipCodeValidator";
let myValidator = new ZipCodeValidator();
//
import {ZipCodeValidator as ZCV} from "./ZipCodeValidator";
let myValidator = new ZCV();
//
import * as validator from "./ZipCodeValidator";
let myValidator = new validator.ZipCodeValidator();
//
import "./my-module.js";
Default exports
1 +2 #3 # JQuery.d.ts4 :declare5 let6 :ref JQuery7 export-default8 #9 # App.ts10 import $ from "JQuery"11 _ $("button.continue").html("Next Step...")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
declare let $: JQuery;
export default $;
//
import $ from "JQuery";
$("button.continue").html("Next Step...");
Default exports of classes and functions
1 +2 #3 # ZipCodeValidator.ts4 export-default5 class ZipCodeValidator6 p numberRegexp7 static8 := /^[0-9]+$/9 m isAcceptable10 param s11 :string12 return s.length === 5 && ZipCodeValidator.numberRegexp.test(s)13 #14 # Test.ts15 import validator from "./ZipCodeValidator"16 let myValidator = new validator()17 #18 # or19 # StaticZipCodeValidator.ts20 const numberRegexp = /^[0-9]+$/21 export-default22 function23 param s24 :string25 return s.length === 5 && numberRegexp.test(s)26 #27 # Test.ts28 import validate from "./StaticZipCodeValidator"29 let strings30 [31 @ "Hello"32 @ "98052"33 @ "101"34 _ strings.forEach35 =>36 param s37 _ console.log38 `lit39 + "40 @ s41 + "42 iif validate(s)43 then " matches"44 else " does not match"45 +
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export default class ZipCodeValidator {
static numberRegexp = /^[0-9]+$/;
isAcceptable(s: string) {
return s.length === 5 && ZipCodeValidator.numberRegexp.test(s);
}
}
//
import validator from "./ZipCodeValidator";
let myValidator = new validator();
//
const numberRegexp = /^[0-9]+$/;
export default function(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
//
import validate from "./StaticZipCodeValidator";
let strings = [
"Hello",
"98052",
"101"
];
strings.forEach(s =>
console.log(`"${s}"${
validate(s)
? " matches"
: " does not match"}
`)
)
Default exports can also be just values:
1 +2 #3 # OneTwoThree.ts4 export-default "123"5 #6 # Log.ts7 import num from "./OneTwoThree"8 _ console.log(num)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export default "123";
//
import num from "./OneTwoThree";
console.log(num);
export = and import = require()
1 +2 #3 # ZipCodeValidator.ts4 let numberRegexp = /^[0-9]+$/5 class ZipCodeValidator6 m isAcceptable7 param s8 :string9 return s.length === 5 && numberRegexp.test(s)10 :export ZipCodeValidator11 #12 # Test.ts13 :import zip14 :require "./ZipCodeValidator"15 let strings16 [17 @ "Hello"18 @ "98052"19 @ "101"20 let validator = new zip()21 _ strings.forEach22 =>23 param s24 _ console.log25 `lit26 + "27 @ s28 + " -29 iif validator.isAcceptable(s)30 then "matches"31 else "does not match"32 +
{
"name": "WizziModelLoadError",
"message": "Error: Tag not recognized: :import, wzElement: undefined, wzName:, row:14, col:9, source:json:/index.ts.ittf\nIn ts Factory, calling loadFromNode.\nLoading ittf document json:/index.ts.ittf (@wizzi/factory.0.8.46)",
"inner": {
"message": "Tag not recognized: :import, wzElement: undefined, wzName:, row:14, col:9, source:json:/index.ts.ittf",
"errorLines": [
"0011 :export ZipCodeValidator",
"0012 # ",
"0013 # Test.ts",
"0014 :import zip",
" ^ Tag not recognized: :import <--- --- --- --- --- ERROR",
"0015 :require \"./ZipCodeValidator\"",
"0016 let strings",
"0017 [ ",
"0018 @ \"Hello\""
],
"stack": "Error\n at new tsModelException (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:6727:23)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:936:23\n at Array.forEach (<anonymous>)\n at statement.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:932:23)\n at tsBase.wzLoadToChildColl (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:114:18)\n at statement.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:198:25)\n at xmodule.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:999:48)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1005:31\n at Array.forEach (<anonymous>)\n at xmodule.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1003:23)"
},
"stack": "Error\n at new tsModelException (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:6727:23)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:936:23\n at Array.forEach (<anonymous>)\n at statement.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:932:23)\n at tsBase.wzLoadToChildColl (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:114:18)\n at statement.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:198:25)\n at xmodule.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:999:48)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1005:31\n at Array.forEach (<anonymous>)\n at xmodule.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1003:23)"
}
Code Generation for Modules
1 +2 :import m3 :require "mod"4 export5 let t = m.something + 16 #7 # AMD / RequireJS SimpleModule.js8 _ define9 [10 @ "require"11 @ "exports"12 @ "./mod"13 function14 param require15 param exports16 param mod_117 set exports.t = mod_1.something + 118 #19 # CommonJS / Node SimpleModule.js20 var mod_1 = require("./mod")21 set exports.t = mod_1.something + 122 #23 # UMD SimpleModule.js24 iife25 param factory26 if typeof module === "object" && typeof module.exports === "object"27 var v = factory(require, exports)28 if v !== undefined29 set module.exports = v30 else31 if typeof define === "function" && define.amd32 _ define33 [34 @ "require"35 @ "exports"36 @ "./mod"37 @ factory38 ()39 function40 param require41 param exports42 var mod_1 = require("./mod")43 set exports.t = mod_1.something + 144 #45 # System SimpleModule.js46 _ System.register47 [48 @ "./mod"49 function50 param exports_151 var mod_152 var t53 return54 {55 [ setters56 function57 param mod_1_158 set mod_1 = mod_1_159 @ execute60 function61 _ exports_162 @ "t"63 set t = mod_1.something + 164 #65 # Native ECMAScript 2015 modules SimpleModule.js66 import67 @ something68 from "./mod"69 export70 var t = something + 1
{
"name": "WizziModelLoadError",
"message": "Error: Tag not recognized: :import, wzElement: undefined, wzName:, row:3, col:9, source:json:/index.ts.ittf\nIn ts Factory, calling loadFromNode.\nLoading ittf document json:/index.ts.ittf (@wizzi/factory.0.8.46)",
"inner": {
"message": "Tag not recognized: :import, wzElement: undefined, wzName:, row:3, col:9, source:json:/index.ts.ittf",
"errorLines": [
"0001 module ",
"0002 + ",
"0003 :import m",
" ^ Tag not recognized: :import <--- --- --- --- --- ERROR",
"0004 :require \"mod\"",
"0005 export ",
"0006 let t = m.something + 1",
"0007 # "
],
"stack": "Error\n at new tsModelException (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:6727:23)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:936:23\n at Array.forEach (<anonymous>)\n at statement.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:932:23)\n at tsBase.wzLoadToChildColl (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:114:18)\n at statement.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:198:25)\n at xmodule.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:999:48)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1005:31\n at Array.forEach (<anonymous>)\n at xmodule.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1003:23)"
},
"stack": "Error\n at new tsModelException (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:6727:23)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:936:23\n at Array.forEach (<anonymous>)\n at statement.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:932:23)\n at tsBase.wzLoadToChildColl (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:114:18)\n at statement.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:198:25)\n at xmodule.loadChild (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:999:48)\n at /app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1005:31\n at Array.forEach (<anonymous>)\n at xmodule.loadFromNode (/app/node_modules/@wizzi/plugin.ts/lib/wizzi/models/ts-model.g.js:1003:23)"
}
Simple Example
1 +2 #3 # Validation.ts4 export5 :interface StringValidator6 :m isAcceptable7 :boolean8 param s9 :string10 #11 # LettersOnlyValidator.ts12 import13 @ StringValidator14 from "./Validation"15 const lettersRegexp = /^[A-Za-z]+$/16 export17 class LettersOnlyValidator18 :implements StringValidator19 m isAcceptable20 param s21 :string22 return lettersRegexp.test(s)23 #24 # ZipCodeValidator.ts25 import26 @ StringValidator27 from "./Validation"28 const numberRegexp = /^[0-9]+$/29 export30 class ZipCodeValidator31 :implements StringValidator32 m isAcceptable33 param s34 :string35 return s.length === 5 && numberRegexp.test(s)36 #37 # Test.ts38 import39 @ StringValidator40 from "./Validation"41 import42 @ ZipCodeValidator43 from "./ZipCodeValidator"44 import45 @ LettersOnlyValidator46 from "./LettersOnlyValidator"47 let strings48 [49 @ "Hello"50 @ "98052"51 @ "101"52 let validators53 :{54 :index55 :ref StringValidator56 param s57 :string58 {59 set validators["ZIP code"] = new ZipCodeValidator()60 set validators["Letters only"] = new LettersOnlyValidator()61 _ strings.forEach62 =>63 param s64 for let name in validators65 _ console.log66 `lit67 + "68 @ s69 + " -70 iif validators[name].isAcceptable(s)71 then "matches"72 else "does not match"73 +74 @ name75 +
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export interface StringValidator {
isAcceptable(s: string): boolean;
}
//
import {StringValidator} from "./Validation";
const lettersRegexp = /^[A-Za-z]+$/;
export class LettersOnlyValidator implements StringValidator {
isAcceptable(s: string) {
return lettersRegexp.test(s);
}
}
//
import {StringValidator} from "./Validation";
const numberRegexp = /^[0-9]+$/;
export class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
//
import {StringValidator} from "./Validation";
import {ZipCodeValidator} from "./ZipCodeValidator";
import {LettersOnlyValidator} from "./LettersOnlyValidator";
let strings = [
"Hello",
"98052",
"101"
];
let validators: {
[s: string]: StringValidator;
} = {};
validators["ZIP code"] = new ZipCodeValidator();
validators["Letters only"] = new LettersOnlyValidator();
strings.forEach((s) => {
for (let name in validators) {
console.log(`"${s}" -${
validators[name].isAcceptable(s)
? "matches"
: "does not match"}
${name}`)
}
}
)
Optional Module Loading
1 +2 #3 # Dynamic Module Loading in Node.js4 :declare5 :function require6 param moduleName7 :string8 :return9 :any10 import11 @ ZipCodeValidator12 as Zip13 from "./ZipCodeValidator"14 if needZipValidation15 let ZipCodeValidator16 :typeof Zip17 _ require("./ZipCodeValidator")18 let validator = new ZipCodeValidator()19 if validator.isAcceptable("...")20 #21 # Sample: Dynamic Module Loading in require.js22 :declare23 :function require24 param moduleNames25 :[26 :string27 param onLoad28 :=>29 :void30 param ...args31 :[32 :any33 :return34 :void35 import36 as Zip37 from "./ZipCodeValidator"38 if needZipValidation39 _ require40 [41 @ "./ZipCodeValidator"42 =>43 param ZipCodeValidator44 :typeof Zip45 let validator = new ZipCodeValidator.ZipCodeValidator()46 if validator.isAcceptable("...")47 #48 # Sample: Dynamic Module Loading in System.js49 :declare50 const System51 :any52 import53 @ ZipCodeValidator54 as Zip55 from "./ZipCodeValidator"56 if needZipValidation57 _ System.import("./ZipCodeValidator").then58 =>59 param ZipCodeValidator60 :typeof Zip61 var x = new ZipCodeValidator()62 if x.isAcceptable("...")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
declare function require(moduleName: string): any;
import {ZipCodeValidator as Zip} from "./ZipCodeValidator";
if (needZipValidation) {
let ZipCodeValidator: typeof Zip = require("./ZipCodeValidator");
let validator = new ZipCodeValidator();
if (validator.isAcceptable("...")) {
}
}
//
declare function require(moduleNames: string[], onLoad: (...args: any[]) => void): void;
import * as Zip from "./ZipCodeValidator";
if (needZipValidation) {
require([
"./ZipCodeValidator"
], (ZipCodeValidator: typeof Zip) => {
let validator = new ZipCodeValidator.ZipCodeValidator();
if (validator.isAcceptable("...")) {
}
}
)
}
//
declare const System: any;
import {ZipCodeValidator as Zip} from "./ZipCodeValidator";
if (needZipValidation) {
System.import("./ZipCodeValidator").then((ZipCodeValidator: typeof Zip) => {
var x = new ZipCodeValidator();
if (x.isAcceptable("...")) {
}
}
)
}
Ambient Modules
1 +2 #3 # node.d.ts(simplified excerpt)4 :declare5 :module "url"6 export7 :interface Url8 :p protocol9 :optional10 :string11 :p hostname12 :optional13 :string14 :p pathname15 :optional16 :string17 export18 :function parse19 param urlStr20 :string21 param parseQueryString22 :optional23 param slashesDenoteHost24 :optional25 :return26 :ref Url27 :module "path"28 export29 :function normalize30 param p31 :string32 :return33 :string34 export35 :function join36 param ...paths37 :[38 :any39 :return40 :string41 export42 var sep43 :string44 #45 # Now we can /// <reference> node.d.ts and then load the modules using import url = require("url"); or import * as URL from "url".46 import47 as URL48 from "url"49 let myUrl = URL.parse("http://www.typescriptlang.org")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
declare module "url" {
export interface Url {
protocol?: string;
hostname?: string;
pathname?: string;
}
export function parse(urlStr: string, parseQueryString?, slashesDenoteHost?): Url;
}
declare module "path" {
export function normalize(p: string): string;
export function join(...paths: any[]): string;
export var sep: string;
}
//
import * as URL from "url";
let myUrl = URL.parse("http://www.typescriptlang.org");
Shorthand ambient modules
1 +2 #3 # declarations.d.ts4 :declare5 :module "hot-new-module"6 #7 # All imports from a shorthand module will have the any type.8 import x9 @ y10 from "hot-new-module"11 _ x(y)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
declare module "hot-new-module" {
}
//
import x, {y} from "hot-new-module";
x(y);
Wildcard module declarations
1 +2 :declare3 :module "*!text"4 const content5 :string6 export-default content7 :module "json!*"8 const value9 :any10 export-default value11 #12 # Now you can import things that match "*!text" or "json!*".13 import fileContent from "./xyz.txt!text"14 import data from "json!http://example.com/data.json"15 _ console.log(data, fileContent)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
declare module "*!text" {
const content: string;
export default content;
}
declare module "json!*" {
const value: any;
export default value;
}
//
import fileContent from "./xyz.txt!text";
import data from "json!http://example.com/data.json";
console.log(data, fileContent);
UMD modules
1 +2 #3 # math-lib.d.ts4 export5 :function isPrime6 param x7 :number8 :return9 :boolean10 :export-ns mathLib11 #12 # The library can then be used as an import within modules:13 import14 @ isPrime15 from "math-lib"16 _ isPrime(2)17 _ mathLib.isPrime(2)18 #19 # It can also be used as a global variable, but only inside of a script. (A script is a file with no imports or exports.)20 _ mathLib.isPrime(2)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
//
export function isPrime(x: number): boolean;
export as namespace
;
//
import {isPrime} from "math-lib";
isPrime(2);
mathLib.isPrime(2);
//
mathLib.isPrime(2);
Export as close to top-level as possible
1 +2 export-default3 class SomeType4 ctor5 #6 # MyFunc.ts7 export-default8 function getThing9 return "thing"10 #11 # Consumer.ts12 import t from "./MyClass"13 import f from "./MyFunc"14 let x = new t()15 _ console.log(f())16 #17 # This is optimal for consumers.18 # They can name your type whatever they want (t in this case) and don’t have to do any excessive dotting to find your objects.19 # If you’re exporting multiple objects, put them all at top- level20 # MyThings.ts21 export22 class SomeType23 export24 function someFunc25 #26 # Conversely when importing:27 # Explicitly list imported names28 # Consumer.ts29 import30 @ SomeType31 @ someFunc32 from "./MyThings"33 let x = new SomeType()34 let y = someFunc()35 #36 # Use the namespace import pattern if you’re importing a large number of things37 # MyLargeModule.ts38 export39 class Dog40 export41 class Cat42 export43 class Tree44 export45 class Flower46 #47 # Consumer.ts48 import49 as myLargeModule50 from "./MyLargeModule.ts"51 let x = new myLargeModule.Dog()
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
export default class SomeType {
constructor() {
}
}
//
export default function getThing() {
return "thing";
}
//
import t from "./MyClass";
import f from "./MyFunc";
let x = new t();
console.log(f());
//
export class SomeType {
}
export function someFunc() {
}
//
import {SomeType, someFunc} from "./MyThings";
let x = new SomeType();
let y = someFunc();
//
export class Dog {
}
export class Cat {
}
export class Tree {
}
export class Flower {
}
//
import * as myLargeModule from "./MyLargeModule.ts";
let x = new myLargeModule.Dog();
Re -export to extend
1 +2 export3 class Calculator4 p current5 :private6 := 07 p memory8 :private9 := 010 p operator11 :private12 :string13 m processDigit14 :protected15 param digit16 :string17 param currentValue18 :number19 if digit >= "0" && digit <= "9"20 return currentValue * 10 + (digit.charCodeAt(0) - "0".charCodeAt(0))21 m processOperator22 :protected23 param operator24 :string25 if26 test27 >=28 [29 @ "+"30 @ "-"31 @ "*"32 @ "/"33 ._ indexOf34 @ operator35 + 036 return operator37 m evaluateOperator38 :protected39 param operator40 :string41 param left42 :number43 param right44 :number45 :return46 :number47 switch this.operator48 case "+"49 return left + right50 case "-"51 return left - right52 case "*"53 return left * right54 case "/"55 return left / right56 m evaluate57 :private58 if this.operator59 set this.memory = this.evaluateOperator(this.operator, this.memory, this.current)60 else61 set this.memory = this.current62 set this.current = 063 m handleChar64 :public65 param char66 :string67 if char === "="68 _ this.evaluate69 return70 else71 let value = this.processDigit(char, this.current)72 if value !== undefined73 set this.current = value74 return75 else76 let value = this.processOperator(char)77 if value !== undefined78 _ this.evaluate79 set this.operator = value80 return81 throw82 new Error83 `lit84 + Unsupported input: '85 @ char86 + '87 m getResult88 :public89 return this.memory90 export91 function test92 param c93 :ref Calculator94 param input95 :string96 for let i = 0; i < input.length; i++97 _ c.handleChar(input[i])98 _ console.log99 `lit100 + result of '101 @ input102 + ' is '103 _ c.getResult104 + '105 #106 # Here is a simple test for the calculator using the exposed test function.107 #108 # TestCalculator.ts109 import110 @ Calculator111 @ test112 from "./Calculator"113 let c = new Calculator()114 _ test(c, "1+2*33/11=")115 #116 # Now to extend this to add support for input with numbers in bases other than 10, let’s create ProgrammerCalculator.ts117 # ProgrammerCalculator.ts118 import119 @ Calculator120 from "./Calculator"121 class ProgrammerCalculator122 super Calculator123 p digits124 static125 [126 @ "0"127 @ "1"128 @ "2"129 @ "3"130 @ "4"131 @ "5"132 @ "6"133 @ "7"134 @ "8"135 @ "9"136 @ "A"137 @ "B"138 @ "C"139 @ "D"140 @ "E"141 @ "F"142 ctor143 param base144 :public145 :number146 _ super147 const maxBase = ProgrammerCalculator.digits.length148 if base <= 0 || base > maxBase149 throw150 new Error151 `lit152 + base has to be within 0 to153 @ maxBase154 + inclusive.155 m processDigit156 :protected157 param digit158 :string159 param currentValue160 :number161 if ProgrammerCalculator.digits.indexOf(digit) >= 0162 return currentValue * this.base + ProgrammerCalculator.digits.indexOf(digit)163 export164 @ ProgrammerCalculator165 as Calculator166 export167 @ test168 from "./Calculator"169 #170 # The new module ProgrammerCalculator exports an API shape similar to that of the original Calculator module,171 # but does not augment any objects in the original module. Here is a test for our ProgrammerCalculator class:172 # TestProgrammerCalculator.ts173 import174 @ Calculator175 @ test176 from "./ProgrammerCalculator"177 let c = new Calculator(2)178 _ test(c, "001+010=")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
export class Calculator {
private current = 0;
private memory = 0;
private operator: string;
protected processDigit(digit: string, currentValue: number) {
if (digit >= "0" && digit <= "9") {
return currentValue * 10 + (digit.charCodeAt(0) - "0".charCodeAt(0));
}
}
protected processOperator(operator: string) {
if (([
"+",
"-",
"*",
"/"
].indexOf(operator)) >= 0) {
return operator;
}
}
protected evaluateOperator(operator: string, left: number, right: number): number {
switch (this.operator) {
case "+": {
return left + right;
}
case "-": {
return left - right;
}
case "*": {
return left * right;
}
case "/": {
return left / right;
}
}
}
private evaluate() {
if (this.operator) {
this.memory = this.evaluateOperator(this.operator, this.memory, this.current);
}
else {
this.memory = this.current;
}
this.current = 0;
}
public handleChar(char: string) {
if (char === "=") {
this.evaluate();
return ;
}
else {
let value = this.processDigit(char, this.current);
if (value !== undefined) {
this.current = value;
return ;
}
else {
let value = this.processOperator(char);
if (value !== undefined) {
this.evaluate();
this.operator = value;
return ;
}
}
}
throw new Error(`Unsupported input: '${char}'`);
}
public getResult() {
return this.memory;
}
}
export function test(c: Calculator, input: string) {
for (let i = 0; i < input.length; i++) {
c.handleChar(input[i]);
}
console.log(`result of '${input}' is '${c.getResult()}'`)
}
//
//
import {Calculator, test} from "./Calculator";
let c = new Calculator();
test(c, "1+2*33/11=");
//
import {Calculator} from "./Calculator";
class ProgrammerCalculator extends Calculator {
constructor(public base: number) {
super();
const maxBase = ProgrammerCalculator.digits.length;
if (base <= 0 || base > maxBase) {
throw new Error(`base has to be within 0 to${maxBase}inclusive.`);
}
}
static digits = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"A",
"B",
"C",
"D",
"E",
"F"
];
protected processDigit(digit: string, currentValue: number) {
if (ProgrammerCalculator.digits.indexOf(digit) >= 0) {
return currentValue * this.base + ProgrammerCalculator.digits.indexOf(digit);
}
}
}
export {ProgrammerCalculator as Calculator};
export {test} from "./Calculator";
//
import {Calculator, test} from "./ProgrammerCalculator";
let c = new Calculator(2);
test(c, "001+010=");
Boolean
1 let isDone2 :boolean3 := false
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let isDone: boolean = false;
Number
1 let decimal2 :number3 := 6
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let decimal: number = 6;
String
1 let color2 :string3 := "blue"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let color: string = "blue";
String literal 1
1 let fullName2 :string3 `lit4 + Bob Bobbington
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let fullName: string = `Bob Bobbington`;
String literal 2
1 let sentence2 :string3 `lit4 + Hello, my name is5 @ fullName6 +
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let sentence: string = `Hello, my name is${fullName}`;
String literal 3
1 let sentence2 :string3 set "Hello, my name is " + fullName + ".\n\n" + "I'll be " + (age + 1) + " years old next month."
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let sentence: string = "Hello, my name is " + fullName + ".\n\n" + "I'll be " + (age + 1) + " years old next month.";
Array 1
1 let list2 :[3 :number4 [5 @ 16 @ 27 @ 3
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let list: number[] = [
1,
2,
3
];
Array 2
1 let list2 :ref Array3 :param number4 [5 @ 16 @ 27 @ 3
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let list: Array<number> = [
1,
2,
3
];
Tuple
1 let x2 :tuple3 :string4 :number
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let x = [string , number];
Enum
1 +2 :enum Color3 @ Red4 @ Green5 @ Blue6 let c7 :ref Color8 := Color.Green9 :enum Color10 @ Red 111 @ Green12 @ Blue13 let c14 :ref Color15 := Color.Green16 :enum Color17 @ Red 118 @ Green 219 @ Blue 420 let c21 :ref Color22 := Color.Green23 :enum Color24 @ Red 125 @ Green26 @ Blue27 let colorName28 :string29 := Color[2]
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
enum Color {
Red ,
Green ,
Blue
}
let c: Color = Color.Green;
enum Color {
Red = 1 ,
Green ,
Blue
}
let c: Color = Color.Green;
enum Color {
Red = 1 ,
Green = 2 ,
Blue = 4
}
let c: Color = Color.Green;
enum Color {
Red = 1 ,
Green ,
Blue
}
let colorName: string = Color[2];
Any, Void, Null, Undefined
1 +2 let notSure3 :any4 := 45 set notSure = "maybe a string instead"6 set notSure = false7 let notSure8 :any9 := 410 _ notSure.ifItExists11 _ notSure.toFixed12 let prettySure13 :ref Object14 := 415 _ prettySure.toFixed16 let list17 :[18 :any19 [20 @ 121 @ true22 @ "free"23 set list[1] = 10024 function warnUser25 :return26 :void27 _ console.log("This is my warning message")28 let unusable29 :void30 := undefined31 let u32 :void33 := undefined34 let n35 :null36 := null
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false;
let notSure: any = 4;
notSure.ifItExists();
notSure.toFixed();
let prettySure: Object = 4;
prettySure.toFixed();
let list: any[] = [
1,
true,
"free"
];
list[1] = 100;
function warnUser(): void {
console.log("This is my warning message");
}
let unusable: void = undefined;
let u: void = undefined;
let n: null = null;
Never
1 +2 function error3 param message4 :string5 :return6 :never7 throw new Error(message)8 function fail9 return error("Something failed")10 function infiniteLoop11 :return12 :never13 while true
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function error(message: string): never {
throw new Error(message);
}
function fail() {
return error("Something failed");
}
function infiniteLoop(): never {
while (true) {
}
}
Object
1 +2 :function create3 param o4 :union5 :object6 :null7 :return8 :void9 let strLength10 :number11 :=12 ()13 @id someValue14 :as15 :string16 . length
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function create(o: object | null): void;
let strLength: number = (someValue as string).length;
Typed functions 1
1 +2 function add3 param x4 :number5 param y6 :number7 :return8 :number9 return x + y10 let myAdd11 function12 param x13 :number14 param y15 :number16 :return17 :number18 return x + y
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function add(x: number, y: number): number {
return x + y;
}
let myAdd = function(x: number, y: number): number {
return x + y;
};
Typed functions 2
1 let myAdd2 :=>3 :number4 param x5 :number6 param y7 :number8 function9 param x10 :number11 param y12 :number13 :return14 :number15 return x + y
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let myAdd: (x: number, y: number) => number = function(x: number, y: number): number {
return x + y;
};
Optional parameters
1 +2 function buildName3 param firstName4 :string5 param lastName6 :string7 :optional8 if lastName9 return firstName + " " + lastName10 else11 return firstName12 # error, too few parameters13 let result1 = buildName("Bob")14 # error, too many parameters15 let result2 = buildName("Bob", "Adams", "Sr.")16 # ah, just right17 let result3 = buildName("Bob", "Adams")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function buildName(firstName: string, lastName?: string) {
if (lastName) {
return firstName + " " + lastName;
}
else {
return firstName;
}
}
// error, too few parameters
let result1 = buildName("Bob");
// error, too many parameters
let result2 = buildName("Bob", "Adams", "Sr.");
// ah, just right
let result3 = buildName("Bob", "Adams");
Rest parameters
1 +2 function buildName3 param firstName4 :string5 param ...restOfName6 :[7 :string8 return firstName + " " + restOfName.join(" ")9 let buildNameFun10 :=>11 :string12 param fname13 :string14 param ...rest15 :[16 :string17 := buildName
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}
let buildNameFun: (fname: string, ...rest: string[]) => string = buildName;
This and arrow functions
1 let deck2 {3 [ suits4 @ "hearts"5 @ "spades"6 @ "clubs"7 @ "diamonds"8 @ cards Array(52)9 @ createCardPicker10 function11 # NOTE: the line below is now an arrow function, allowing us to capture 'this' right here12 return13 =>14 let pickedCard = Math.floor(Math.random() * 52)15 let pickedSuit = Math.floor(pickedCard / 13)16 return17 {18 @ suit this.suits[pickedSuit]19 @ card pickedCard % 13
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let deck = {
suits: [
"hearts",
"spades",
"clubs",
"diamonds"
],
cards: Array(52),
createCardPicker: // NOTE: the line below is now an arrow function, allowing us to capture 'this' right here
function() {
return () => {
let pickedCard = Math.floor(Math.random() * 52);
let pickedSuit = Math.floor(pickedCard / 13);
return {
suit: this.suits[pickedSuit],
card: pickedCard % 13
};
}
;
}
};
This parameters in callbacks
1 +2 :interface UIElement3 :m addClickListener4 :void5 param onclick6 :=>7 :void8 param this9 :void10 param e11 :ref Event12 class Handler13 p info14 :string15 m onClickBad16 param this17 :ref Handler18 param e19 :ref Event20 set this.info = e.message
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface UIElement {
addClickListener(onclick: (this: void, e: Event) => void): void;
}
class Handler {
info: string;
onClickBad(this: Handler, e: Event) {
this.info = e.message;
}
}
Overloads 1
1 +2 let suits3 [4 @ "hearts"5 @ "spades"6 @ "clubs"7 @ "diamonds"8 function pickCard9 param x10 :return11 :any12 if typeof x == "object"13 let pickedCard = Math.floor(Math.random() * x.length)14 return pickedCard15 else16 # Otherwise just let them pick the card17 if typeof x == "number"18 let pickedSuit = Math.floor(x / 13)19 return20 {21 @ suit suits[pickedSuit]22 @ card x % 13
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let suits = [
"hearts",
"spades",
"clubs",
"diamonds"
];
function pickCard(x): any {
if (typeof x == "object") {
let pickedCard = Math.floor(Math.random() * x.length);
return pickedCard;
}
// Otherwise just let them pick the card
else {
if (typeof x == "number") {
let pickedSuit = Math.floor(x / 13);
return {
suit: suits[pickedSuit],
card: x % 13
};
}
}
}
Overloads 2
1 +2 let suits3 [4 @ "hearts"5 @ "spades"6 @ "clubs"7 @ "diamonds"8 :function pickCard9 param x10 :[11 :{12 :p suit13 :string14 :p card15 :number16 :return17 :number18 :function pickCard19 param x20 :number21 :return22 :{23 :p suit24 :string25 :p card26 :number27 function pickCard28 param x29 :return30 :any31 # if so, they gave us the deck and we'll pick the card32 if typeof x == "object"33 let pickedCard = Math.floor(Math.random() * x.length)34 return pickedCard35 else36 # Otherwise just let them pick the card37 if typeof x == "number"38 let pickedSuit = Math.floor(x / 13)39 return40 {41 @ suit suits[pickedSuit]42 @ card x % 13
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
let suits = [
"hearts",
"spades",
"clubs",
"diamonds"
];
function pickCard(x: {
suit: string;
card: number;
}[]): number;
function pickCard(x: number): {
suit: string;
card: number;
};
// if so, they gave us the deck and we'll pick the card
function pickCard(x): any {
if (typeof x == "object") {
let pickedCard = Math.floor(Math.random() * x.length);
return pickedCard;
}
// Otherwise just let them pick the card
else {
if (typeof x == "number") {
let pickedSuit = Math.floor(x / 13);
return {
suit: suits[pickedSuit],
card: x % 13
};
}
}
}
Simple class
1 class Greeter2 p greeting3 :string4 ctor5 param message6 :string7 set this.greeting = message8 m greet9 return "Hello, " + this.greeting
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Greeter {
constructor(message: string) {
this.greeting = message;
}
greeting: string;
greet() {
return "Hello, " + this.greeting;
}
}
let greeter = new Greeter("world");
Class extension
1 class Animal2 m move3 param distanceInMeters4 :number5 := 06 _ console.log7 `lit8 + Animal moved9 @ distanceInMeters10 + m.
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Animal {
move(distanceInMeters: number = 0) {
console.log(`Animal moved${distanceInMeters}m.`)
}
}
class Dog extends Animal {
bark() {
console.log('Woof! Woof!');
}
}
Complex class example
1 +2 class Animal3 p name4 :string5 ctor6 param theName7 :string8 set this.name = theName9 m move10 param distanceInMeters11 :number12 := 013 _ console.log14 `lit15 +16 @ this.name17 + moved18 @ distanceInMeters19 + m.20 class Snake21 super Animal22 ctor23 param name24 :string25 _ super(name)26 m move27 param distanceInMeters = 528 _ console.log("Slithering...")29 _ super.move(distanceInMeters)30 class Horse31 super Animal32 ctor33 param name34 :string35 _ super(name)36 m move37 param distanceInMeters = 4538 _ console.log("Galloping...")39 _ super.move(distanceInMeters)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Animal {
constructor(theName: string) {
this.name = theName;
}
name: string;
move(distanceInMeters: number = 0) {
console.log(`${this.name}moved${distanceInMeters}m.`)
}
}
class Snake extends Animal {
constructor(name: string) {
super(name);
}
move(distanceInMeters = 5) {
console.log("Slithering...");
super.move(distanceInMeters);
}
}
class Horse extends Animal {
constructor(name: string) {
super(name);
}
move(distanceInMeters = 45) {
console.log("Galloping...");
super.move(distanceInMeters);
}
}
Class accessors
1 +2 class Animal3 p name4 :private5 :string6 ctor7 param theName8 :string9 set this.name = theName10 class Rhino11 super Animal12 ctor13 _ super("Rhino")14 class Employee15 p name16 :private17 :string18 ctor19 param theName20 :string21 set this.name = theName22 let animal = new Animal("Goat")23 let rhino = new Rhino()24 let employee = new Employee("Bob")25 set animal = rhino26 set animal = employee
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Animal {
constructor(theName: string) {
this.name = theName;
}
private name: string;
}
class Rhino extends Animal {
constructor() {
super("Rhino");
}
}
class Employee {
constructor(theName: string) {
this.name = theName;
}
private name: string;
}
let animal = new Animal("Goat");
let rhino = new Rhino();
let employee = new Employee("Bob");
animal = rhino;
animal = employee;
Class accessors
1 +2 class Person3 p name4 :protected5 :string6 ctor7 param name8 :string9 set this.name = name10 class Employee11 super Person12 p department13 :private14 :string15 ctor16 param name17 :string18 param department19 :string20 _ super(name)21 set this.department = department22 m getElevatorPitch23 :public24 return25 `lit26 + Hello, my name is27 @ this.name28 + and I work in29 @ this.department30 + .
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Person {
constructor(name: string) {
this.name = name;
}
protected name: string;
}
class Employee extends Person {
constructor(name: string, department: string) {
super(name);
this.department = department;
}
private department: string;
public getElevatorPitch() {
return `Hello, my name is${this.name}and I work in${this.department}.`;
}
}
Readonly modifier
1 +2 class Octopus3 p name4 :readonly5 :string6 p numberOfLegs7 :readonly8 :number9 := 810 ctor11 param theName12 :string13 set this.name = theName14 let dad = new Octopus("Man with the 8 strong legs")15 set dad.name = "Man with the 3-piece suit"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Octopus {
constructor(theName: string) {
this.name = theName;
}
readonly name: string;
readonly numberOfLegs: number = 8;
}
let dad = new Octopus("Man with the 8 strong legs");
dad.name = "Man with the 3-piece suit";
Parameter properties
1 +2 class Octopus3 p numberOfLegs4 :readonly5 :number6 := 87 ctor8 param9 :readonly10 :string
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Octopus {
constructor(readonly : string) {
}
readonly numberOfLegs: number = 8;
}
Static members
1 class Grid2 p origin3 static4 {5 @ x 06 @ y 07 m calculateDistanceFromOrigin8 param point9 :{10 :p x11 :number12 :p y13 :number14 let xDist = (point.x - Grid.origin.x)15 let yDist = (point.y - Grid.origin.y)16 return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale17 ctor18 param scale19 :public20 :number
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Grid {
constructor(public scale: number) {
}
static origin = {
x: 0,
y: 0
}
;
calculateDistanceFromOrigin(point: {
x: number;
y: number;
}) {
let xDist = (point.x - Grid.origin.x);
let yDist = (point.y - Grid.origin.y);
return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale;
}
}
Abstract classes 1
1 +2 class Animal3 :abstract4 :m makeSound5 :abstract6 :return7 :void8 m move9 :return10 :void11 _ console.log("roaming the earth...")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
abstract class Animal {
abstract makeSound(): void {
}
move(): void {
console.log("roaming the earth...");
}
}
Abstract classes 2
1 +2 class Department3 :abstract4 ctor5 param name6 :public7 :string8 m printName9 :return10 :void11 _ console.log("Department name: " + this.name)12 :m printMeeting13 :abstract14 :return15 :void16 class AccountingDepartment17 super Department18 ctor19 _ super("Accounting and Auditing")20 m printMeeting21 :return22 :void23 _ console.log("The Accounting Department meets each Monday at 10am.")24 m generateReports25 :return26 :void27 _ console.log("Generating accounting reports...")28 let department29 :ref Department30 set department = new Department()31 set department = new AccountingDepartment()32 _ department.printName33 _ department.printMeeting34 _ department.generateReports35 # error: method doesn't exist on declared abstract type
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
abstract class Department {
constructor(public name: string) {
}
printName(): void {
console.log("Department name: " + this.name);
}
abstract printMeeting(): void {
}
}
class AccountingDepartment extends Department {
constructor() {
super("Accounting and Auditing");
}
printMeeting(): void {
console.log("The Accounting Department meets each Monday at 10am.");
}
generateReports(): void {
console.log("Generating accounting reports...");
}
}
let department: Department;
department = new Department();
department = new AccountingDepartment();
department.printName();
department.printMeeting();
department.generateReports();
// error: method doesn't exist on declared abstract type
Static members
1 +2 class Greeter3 p standardGreeting4 static5 := "Hello, there"6 p greeting7 :string8 m greet9 if this.greeting10 return "Hello, " + this.greeting11 else12 return Greeter.standardGreeting
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Greeter {
static standardGreeting = "Hello, there";
greeting: string;
greet() {
if (this.greeting) {
return "Hello, " + this.greeting;
}
else {
return Greeter.standardGreeting;
}
}
}
Class extended by interface
1 +2 class Point3 p x4 :number5 p y6 :number7 :interface Point3d8 :extends Point9 :p z10 :number11 let point3d12 :ref Point3d13 {14 @ x 115 @ y 216 @ z 3
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Point {
x: number;
y: number;
}
interface Point3d extends Point {
z: number;
}
let point3d: Point3d = {
x: 1,
y: 2,
z: 3
};
Simple interface
1 :interface LabelledValue2 :p label3 :string
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface LabelledValue {
label: string;
}
Reference to interface
1 +2 function printLabel3 param labelledObj4 :ref LabelledValue5 _ console.log(labelledObj.label)6 let myObj7 {8 @ size 109 @ label "Size 10 Object"10 _ printLabel(myObj)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
function printLabel(labelledObj: LabelledValue) {
console.log(labelledObj.label);
}
let myObj = {
size: 10,
label: "Size 10 Object"
};
printLabel(myObj);
Optional properties
1 :interface SquareConfig2 :p color3 :optional4 :string5 :p width6 :optional7 :number
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface SquareConfig {
color?: string;
width?: number;
}
Optional properties 2
1 +2 :interface SquareConfig3 :p color4 :optional5 :string6 :p width7 :optional8 :number9 function createSquare10 param config11 :ref SquareConfig12 :return13 :{14 :p color15 :string16 :p area17 :number18 let newSquare19 {20 @ color "white"21 @ area 10022 if config.clor23 # Error: Property 'clor' does not exist on type 'SquareConfig'24 set newSquare.color = config.clor25 if config.width26 set newSquare.area = config.width * config.width27 return newSquare28 let mySquare29 _ createSquare30 {31 @ color "black"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface SquareConfig {
color?: string;
width?: number;
}
function createSquare(config: SquareConfig): {
color: string;
area: number;
} {
let newSquare = {
color: "white",
area: 100
};
// Error: Property 'clor' does not exist on type 'SquareConfig'
if (config.clor) {
newSquare.color = config.clor;
}
if (config.width) {
newSquare.area = config.width * config.width;
}
return newSquare;
}
let mySquare = createSquare({
color: "black"
});
Readonly properties
1 +2 :interface Point3 :p x4 :number5 :p y6 :number7 # You can construct a Point by assigning an object literal.After the assignment, x and y can’t be changed.8 let p19 :ref Point10 {11 @ x 1012 @ y 2013 # error!14 set p1.x = 5
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface Point {
x: number;
y: number;
}
// You can construct a Point by assigning an object literal.After the assignment, x and y can’t be changed.
let p1: Point = {
x: 10,
y: 20
};
// error!
p1.x = 5;
Readonly vs const
1 +2 :interface SquareConfig3 :p color4 :optional5 :string6 :p width7 :optional8 :number9 function createSquare10 param config11 :ref SquareConfig12 :return13 :{14 :p color15 :string16 :p area17 :number18 let mySquare19 _ createSquare20 {21 @ colour "red"22 @ width 100
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface SquareConfig {
color?: string;
width?: number;
}
function createSquare(config: SquareConfig): {
color: string;
area: number;
} {
}
let mySquare = createSquare({
colour: "red",
width: 100
});
Call signature
1 +2 :interface SearchFunc3 :call4 :boolean5 param source6 :string7 param subString8 :string9 let mySearch10 :ref SearchFunc11 set mySearch =12 function13 param source14 :string15 param subString16 :string17 let result = source.search(subString)18 return result > -1
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface SearchFunc {
(source: string, subString: string): boolean;
}
let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
let result = source.search(subString);
return result > -1;
}
;
Index signature
1 +2 :interface StringArray3 :index4 :string5 param index6 :number7 let myArray8 :ref StringArray9 set myArray =10 [11 @ "Bob"12 @ "Fred"13 let myStr14 :string15 := myArray[0]
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface StringArray {
[index: number]: string;
}
let myArray: StringArray;
myArray = [
"Bob",
"Fred"
];
let myStr: string = myArray[0];
Index signature 2
1 +2 class Animal3 p name4 :string5 class Dog6 super Animal7 p breed8 :string9 :interface NotOkay10 :index11 :ref Animal12 param x13 :number14 :index15 :ref Dog16 param x17 :string
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Animal {
name: string;
}
class Dog extends Animal {
breed: string;
}
interface NotOkay {
[x: number]: Animal;
[x: string]: Dog;
}
Index signature 3
1 :interface NumberDictionary2 :index3 :number4 param index5 :string6 :p length7 :number8 :p name9 :string
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface NumberDictionary {
[index: string]: number;
length: number;
name: string;
}
Readonly index signature 3
1 +2 :interface ReadonlyStringArray3 :index4 :string5 :readonly6 param index7 :number8 let myArray9 :ref ReadonlyStringArray10 [11 @ "Alice"12 @ "Bob"13 set myArray[2] = "Mallory"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface ReadonlyStringArray {
readonly [index: number]: string;
}
let myArray: ReadonlyStringArray = [
"Alice",
"Bob"
];
myArray[2] = "Mallory";
Class Types
1 +2 :interface ClockInterface3 :p currentTime4 :ref Date5 class Clock6 :implements ClockInterface7 p currentTime8 :ref Date9 ctor10 param h11 :number12 param m13 :number14 :interface ClockInterface15 :p currentTime16 :ref Date17 :m setTime18 param d19 :ref Date20 class Clock21 :extends ClockInterface22 p currentTime23 :ref Date24 m setTime25 param d26 :ref Date27 set this.currentTime = d28 ctor29 param h30 :number31 param m32 :number
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface ClockInterface {
currentTime: Date;
}
class Clock implements ClockInterface {
constructor(h: number, m: number) {
}
currentTime: Date;
}
interface ClockInterface {
currentTime: Date;
setTime(d: Date);
}
class Clock extends ClockInterface {
constructor(h: number, m: number) {
}
currentTime: Date;
setTime(d: Date) {
this.currentTime = d;
}
}
static and instance sides of classes - fails
1 +2 :interface ClockConstructor3 :new4 param hour5 :number6 param minute7 :number8 class Clock9 :implements ClockConstructor10 p currentTime11 :ref Date12 ctor13 param h14 :number15 param m16 :number
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface ClockConstructor {
(hour: number, minute: number);
}
class Clock implements ClockConstructor {
constructor(h: number, m: number) {
}
currentTime: Date;
}
static and instance sides of classes - succeds
1 +2 :interface ClockConstructor3 :new4 :ref ClockInterface5 param hour6 :number7 param minute8 :number9 :interface ClockInterface10 :m tick11 function createClock12 param ctor13 :ref ClockConstructor14 param hour15 :number16 param minute17 :number18 :return19 :ref ClockInterface20 return new ctor(hour, minute)21 class DigitalClock22 :implements ClockInterface23 ctor24 param h25 :number26 param m27 :number28 m tick29 _ console.log("beep beep")30 class AnalogClock31 :implements ClockInterface32 ctor33 param h34 :number35 param m36 :number37 m tick38 _ console.log("tick tock")39 let digital = createClock(DigitalClock, 12, 17)40 let analog = createClock(AnalogClock, 7, 32)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface ClockConstructor {
(hour: number, minute: number): ClockInterface;
}
interface ClockInterface {
tick();
}
function createClock(ctor: ClockConstructor, hour: number, minute: number): ClockInterface {
return new ctor(hour, minute);
}
class DigitalClock implements ClockInterface {
constructor(h: number, m: number) {
}
tick() {
console.log("beep beep");
}
}
class AnalogClock implements ClockInterface {
constructor(h: number, m: number) {
}
tick() {
console.log("tick tock");
}
}
let digital = createClock(DigitalClock, 12, 17);
let analog = createClock(AnalogClock, 7, 32);
Extending Interfaces 1
1 +2 :interface Shape3 :p color4 :string5 :interface Square6 :extends Shape7 :p sideLength8 :number9 let square10 {11 :as12 :ref Square13 set square.color = "blue"14 set square.sideLength = 10
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface Shape {
color: string;
}
interface Square extends Shape {
sideLength: number;
}
let square = {} as Square;
square.color = "blue";
square.sideLength = 10;
Extending Interfaces 2
1 +2 :interface Shape3 :p color4 :string5 :interface PenStroke6 :p penWidth7 :number8 :interface Square9 :extends Shape10 :extends PenStroke11 :p sideLength12 :number13 let square14 {15 :as16 :ref Square17 set square.color = "blue"18 set square.sideLength = 1019 set square.penWidth = 5
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface Shape {
color: string;
}
interface PenStroke {
penWidth: number;
}
interface Square extends Shape, PenStroke {
sideLength: number;
}
let square = {} as Square;
square.color = "blue";
square.sideLength = 10;
square.penWidth = 5;
Hybrid Types
1 +2 :interface Counter3 :call4 :string5 param start6 :number7 :p interval8 :number9 :m reset10 :void11 function getCounter12 :return13 :ref Counter14 let counter15 :as16 :ref Counter17 function18 param start19 :number20 set counter.interval = 12321 set counter.reset =22 function23 return counter24 let c = getCounter()25 _ c(10)26 _ c.reset27 set c.interval = 5
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
function getCounter(): Counter {
let counter = as Counterfunction(start: number) {
};
counter.interval = 123;
counter.reset = function() {
}
;
return counter;
}
let c = getCounter();
c(10);
c.reset();
c.interval = 5;
Class with private property
1 class Control2 p state3 :private4 :any
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Control {
private state: any;
}
Interface extending class
interface SelectableControl extends Control {
select(): void;
}
1 :interface SelectableControl2 :extends Control3 :m select4 :void
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
interface SelectableControl extends Control {
select(): void;
}
Derived class extending interface
class Button extends Control implements SelectableControl {
select() {}
}
1 class Button2 super Control3 :implements SelectableControl4 m select
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Button extends Control implements SelectableControl {
select() {
}
}
Derived class
class TextBox extends Control {
select() {}
}
1 class TextBox2 super Control3 m select
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class TextBox extends Control {
select() {
}
}
Class extending interface
// Error: Property 'state' is missing in type 'Image'.
class Image implements SelectableControl {
select() {}
}
1 class Image2 :implements SelectableControl3 m select
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:19 GMT
*/
class Image implements SelectableControl {
select() {
}
}
Identity function with any
1 function identity2 param arg3 :any4 :return5 :any6 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function identity(arg: any): any {
return arg;
}
Identity function with type variable
1 function identity2 :< T3 param arg4 :ref T5 :return6 :ref T7 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function identity<T>(arg: T): T {
return arg;
}
Type argument
1 let output2 _ identity3 :< string4 @ "myString"
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
let output = identity(string, "myString");
Length property fails
1 function loggingIdentity2 :< T3 param arg4 :ref T5 :return6 :ref T7 _ console.log(arg.length)8 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function loggingIdentity<T>(arg: T): T {
console.log(arg.length);
return arg;
}
Length property succeds 1
1 +2 function loggingIdentity3 :< T4 param arg5 :[6 :ref T7 :return8 :[9 :ref T10 _ console.log(arg.length)11 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function loggingIdentity<T>(arg: T[]): T[] {
console.log(arg.length);
return arg;
}
Length property succeds 2
1 function loggingIdentity2 :< T3 param arg4 :ref Array5 :ref T6 :return7 :ref Array8 :ref T9 _ console.log(arg.length)10 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function loggingIdentity<T>(arg: <Array>T): <Array>T {
console.log(arg.length);
return arg;
}
Generic function
1 +2 function identity3 :< T4 param arg5 :ref T6 :return7 :ref T8 return arg9 let myIdentity10 :=>11 :ref T12 param arg13 :ref T14 := identity
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function identity<T>(arg: T): T {
return arg;
}
let myIdentity: (arg: T) => T = identity;
Call signature object literal type
1 +2 function identity3 :< T4 param arg5 :ref T6 :return7 :ref T8 return arg9 let myIdentity10 :{11 :call12 :< T13 :ref T14 param arg15 :ref T16 := identity
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function identity<T>(arg: T): T {
return arg;
}
let myIdentity: {
T(arg: T): T;
} = identity;
Generic interface
1 +2 :interface GenericIdentityFn3 :< T4 :call5 :ref T6 param arg7 :ref T8 function identity9 :< T10 param arg11 :ref T12 :return13 :ref T14 return arg15 let myIdentity16 :ref GenericIdentityFn17 :param number18 := identity
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface GenericIdentityFn<T> {
(arg: T): T;
}
function identity<T>(arg: T): T {
return arg;
}
let myIdentity: GenericIdentityFn<number> = identity;
Generic Classes
1 class GenericNumber2 :< T3 p zeroValue4 :ref T5 p add6 :=>7 :ref T8 param x9 :ref T10 param y11 :ref T
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
class GenericNumber<T> {
zeroValue: T;
add: (x: T, y: T) => T;
}
Generic Constraints - fails
1 function loggingIdentity2 :< T3 param arg4 :ref T5 :return6 :ref T7 _ console.log(arg.length)8 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function loggingIdentity<T>(arg: T): T {
console.log(arg.length);
return arg;
}
Generic Constraints - succeds
1 +2 :interface Lengthwise3 :p length4 :number5 function loggingIdentity6 :< T7 :ref Lengthwise8 param arg9 :ref T10 :return11 :ref T12 _ console.log(arg.length)13 return arg
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface Lengthwise {
length: number;
}
function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length);
return arg;
}
Type Parameters in Generic Constraints
1 +2 function getProperty3 :< T4 :< K5 :keyof6 :ref T7 param obj8 :ref T9 param key10 :ref K11 return obj[key]12 let x13 {14 @ a 115 @ b 216 @ c 317 @ d 418 _ getProperty(x, "a")19 _ getProperty(x, "m")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function getProperty<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
let x = {
a: 1,
b: 2,
c: 3,
d: 4
};
getProperty(x, "a");
getProperty(x, "m");
Class Types in Generics
1 function create2 :< T3 param c4 :{5 :new6 :ref T7 :return8 :ref T9 return new c()
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function create<T>(c: {
(): T;
}): T {
return new c();
}
Prototype property
1 +2 class BeeKeeper3 p hasMask4 :boolean5 class ZooKeeper6 p nametag7 :string8 class Animal9 p numLegs10 :number11 class Bee12 super Animal13 p keeper14 :ref BeeKeeper15 class Lion16 super Animal17 p keeper18 :ref ZooKeeper19 function createInstance20 :< A21 :ref Animal22 param c23 :ctor24 :ref A25 :return26 :ref A27 return new c()28 var x = createInstance(Lion).keeper.nametag29 var y = createInstance(Bee).keeper.hasMask
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
class BeeKeeper {
hasMask: boolean;
}
class ZooKeeper {
nametag: string;
}
class Animal {
numLegs: number;
}
class Bee extends Animal {
keeper: BeeKeeper;
}
class Lion extends Animal {
keeper: ZooKeeper;
}
function createInstance<A extends Animal>(c = *** :ctor ;
): A {
return new c();
}
var x = createInstance(Lion).keeper.nametag;
var y = createInstance(Bee).keeper.hasMask;
Intersection Types
1 +2 function extend3 :< T4 :< U5 param first6 :ref T7 param second8 :ref U9 :return10 :intersect11 :ref T12 :ref U13 let result14 :as15 :intersect16 :ref T17 :ref U18 { {}19 for let id in first20 set =21 @expr22 ()23 @id result24 :as25 :any26 .[ id27 @expr28 ()29 @id first30 :as31 :any32 .[ id33 for let id in second34 if !result.hasOwnProperty(id)35 set =36 @expr37 ()38 @id result39 :as40 :any41 .[ id42 @expr43 ()44 @id second45 :as46 :any47 .[ id48 return result49 class Person50 ctor51 param name52 :string53 :interface Loggable54 :m log55 :void56 class ConsoleLogger57 :extends Loggable58 m log59 var jim = extend(new Person("Jim"), new ConsoleLogger())60 var n = jim.name61 _ jim.log
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function extend<T, U>(first: T, second: U): T & U {
let result = as T & U;
for (let id in first) {
(result as any)[id] = (first as any)[id];
}
for (let id in second) {
if (!result.hasOwnProperty(id)) {
(result as any)[id] = (second as any)[id];
}
}
return result;
}
class Person {
constructor(name: string) {
}
}
interface Loggable {
log(): void;
}
class ConsoleLogger extends Loggable {
log() {
}
}
var jim = extend(new Person("Jim"), new ConsoleLogger());
var n = jim.name;
jim.log();
Union Types - fail at run time
1 +2 function padLeft3 param value4 :string5 param padding6 :any7 if typeof padding === "number"8 return Array(padding + 1).join(" ") + value9 if typeof padding === "string"10 return padding + value11 throw12 new Error13 `lit14 + Expected string or number, got '15 @ padding16 + '.17 _ padLeft("Hello world", 4)18 let indentedString = padLeft("Hello world", true)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function padLeft(value: string, padding: any) {
if (typeof padding === "number") {
return Array(padding + 1).join(" ") + value;
}
if (typeof padding === "string") {
return padding + value;
}
throw new Error(`Expected string or number, got '${padding}'.`);
}
padLeft("Hello world", 4);
let indentedString = padLeft("Hello world", true);
Union Types - succeds at run time
1 +2 function padLeft3 param value4 :string5 param padding6 :union7 :string8 :number9 let indentedString = padLeft("Hello world", true)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function padLeft(value: string, padding: string | number) {
}
let indentedString = padLeft("Hello world", true);
Union Types - common members
1 +2 :interface Bird3 :m fly4 :m layEggs5 :interface Fish6 :m swim7 :m layEggs8 function getSmallPet9 :return10 :union11 :ref Fish12 :ref Bird13 let pet = getSmallPet()14 _ pet.layEggs15 _ pet.swim
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface Bird {
fly();
layEggs();
}
interface Fish {
swim();
layEggs();
}
function getSmallPet(): Fish | Bird {
}
let pet = getSmallPet();
pet.layEggs();
pet.swim();
Type Guards and Differentiating Types
1 +2 let pet = getSmallPet()3 if4 test5 @expr6 ()7 @id pet8 :as9 :ref Fish10 . swim11 _12 ()13 @id pet14 :as15 :ref Fish16 ._ swim17 else18 _19 ()20 @id pet21 :as22 :ref Bird23 ._ fly
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
let pet = getSmallPet();
if ((pet as Fish).swim) {
(pet as Fish).swim()
}
else {
(pet as Bird).fly()
}
User - Defined Type Guards
1 +2 function isFish3 param pet4 :union5 :ref Fish6 :ref Bird7 :return8 :predicate pet9 :ref Fish10 return11 !==12 @expr13 ()14 @id pet15 :as16 :ref Fish17 . swim18 + undefined19 function isNumber20 param x21 :any22 :return23 :predicate x24 :number25 return typeof x === "number"26 function isString27 param x28 :any29 :return30 :predicate x31 :string32 return typeof x === "string"33 function padLeft34 param value35 :string36 param padding37 :union38 :string39 :number40 if isNumber(padding)41 return Array(padding + 1).join(" ") + value42 if isString(padding)43 return padding + value44 throw45 new Error46 `lit47 + Expected string or number, got '48 @ padding49 + '.
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function isFish(pet: Fish | Bird): pet is Fish {
return ((pet as Fish).swim) !== undefined;
}
function isNumber(x: any): x is number {
return typeof x === "number";
}
function isString(x: any): x is string {
return typeof x === "string";
}
function padLeft(value: string, padding: string | number) {
if (isNumber(padding)) {
return Array(padding + 1).join(" ") + value;
}
if (isString(padding)) {
return padding + value;
}
throw new Error(`Expected string or number, got '${padding}'.`);
}
Instanceof type guards
1 +2 :interface Padder3 :m getPaddingString4 :string5 class SpaceRepeatingPadder6 :extends Padder7 ctor8 param numSpaces9 :private10 :number11 m getPaddingString12 return Array(this.numSpaces + 1).join(" ")13 class StringPadder14 :extends Padder15 ctor16 param value17 :private18 :string19 m getPaddingString20 return this.value21 function getRandomPadder22 return23 iif Math.random() < 0.524 then new SpaceRepeatingPadder(4)25 else new StringPadder(" ")26 # Type is 'SpaceRepeatingPadder | StringPadder'27 let padder28 :ref Padder29 _ getRandomPadder30 if padder instanceof SpaceRepeatingPadder31 var x = padder32 # type narrowed to 'SpaceRepeatingPadder'33 if padder instanceof StringPadder34 var x = padder35 # type narrowed to 'StringPadder'
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface Padder {
getPaddingString(): string;
}
class SpaceRepeatingPadder extends Padder {
constructor(private numSpaces: number) {
}
getPaddingString() {
return Array(this.numSpaces + 1).join(" ");
}
}
class StringPadder extends Padder {
constructor(private value: string) {
}
getPaddingString() {
return this.value;
}
}
function getRandomPadder() {
return Math.random() < 0.5 ? new SpaceRepeatingPadder(4) : new StringPadder(" ");
}
// Type is 'SpaceRepeatingPadder | StringPadder'
let padder: Padder = getRandomPadder();
// type narrowed to 'SpaceRepeatingPadder'
if (padder instanceof SpaceRepeatingPadder) {
var x = padder;
}
// type narrowed to 'StringPadder'
if (padder instanceof StringPadder) {
var x = padder;
}
Nullable types
1 +2 let s = "foo"3 set s = null4 let sn5 :union6 :string7 :null8 := "bar"9 set sn = null10 set sn = undefined11 function f12 param x13 :number14 param15 :number16 :optional17 return x + y || 018 _ f(1, 2)19 _ f(1)20 _ f(1, undefined)21 _ f(1, null)22 class C23 p a24 :number25 p b26 :number27 let c = new C()28 set c.a = 1229 set c.a = undefined30 set c.b = 1331 set c.b = undefined32 set c.b = null
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
let s = "foo";
s = null;
let sn: string | null = "bar";
sn = null;
sn = undefined;
function f(x: number, ?: number) {
return x + y || 0;
}
f(1, 2);
f(1);
f(1, undefined);
f(1, null);
class C {
a: number;
b: number;
}
let c = new C();
c.a = 12;
c.a = undefined;
c.b = 13;
c.b = undefined;
c.b = null;
Type guards and type assertions
1 +2 function f3 param sn4 :union5 :string6 :null7 :return8 :string9 if sn == null10 return "default"11 else12 return sn13 function f14 param sn15 :union16 :string17 :null18 :return19 :string20 return sn || "default"21 function broken22 param name23 :union24 :string25 :null26 :return27 :string28 function postfix29 param epithet30 :string31 return name.charAt(0) + '. the ' + epithet32 set name = name || "Bob"33 return postfix("great")34 function fixed35 param name36 :union37 :string38 :null39 :return40 :string41 function postfix42 param epithet43 :string44 return45 op+46 op+47 _48 ._ charAt49 @ 050 + '. the '51 + epithet52 set name = name || "Bob"53 return postfix("great")
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function f(sn: string | null): string {
if (sn == null) {
return "default";
}
else {
return sn;
}
}
function f(sn: string | null): string {
return sn || "default";
}
function broken(name: string | null): string {
function postfix(epithet: string) {
return name.charAt(0) + '. the ' + epithet;
}
name = name || "Bob";
return postfix("great");
}
function fixed(name: string | null): string {
function postfix(epithet: string) {
return ((.charAt(0)
) + '. the ') + epithet;
}
name = name || "Bob";
return postfix("great");
}
Type Aliases
1 +2 :type Name3 :string4 :type NameResolver5 :=>6 :string7 :type NameOrResolver8 :union9 :ref Name10 :ref NameResolver11 function getName12 param n13 :ref NameOrResolver14 :return15 :ref Name16 if typeof n === "string"17 return n18 else19 return n()20 :type Container21 :< T22 :{23 :p value24 :ref T25 :type Tree26 :< T27 :{28 :p value29 :ref T30 :p left31 :ref Tree32 :ref T33 :p right34 :ref Tree35 :ref T36 :type LinkedList37 :< T38 :intersect39 :ref T40 :{41 :p next42 :ref LinkedList43 :ref T44 :interface Person45 :p name46 :string47 var people48 :ref LinkedList49 :ref Person50 var s = people.name51 var s = people.next.name52 var s = people.next.next.name53 var s = people.next.next.next.name54 :type Yikes55 :ref Array56 :ref Yikes
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type Name = string;
type NameResolver = () => string;
type NameOrResolver = Name | NameResolver;
function getName(n: NameOrResolver): Name {
if (typeof n === "string") {
return n;
}
else {
return n();
}
}
type Container<T> = {
value: T;
};
type Tree<T> = {
value: T;
left: <Tree>T;
right: <Tree>T;
};
type LinkedList<T> = T & {
next: <LinkedList>T;
};
interface Person {
name: string;
}
var people: <LinkedList>Person;
var s = people.name;
var s = people.next.name;
var s = people.next.next.name;
var s = people.next.next.next.name;
type Yikes = <Array>Yikes;
Interfaces vs.Type Aliases
1 +2 :type Alias3 :{4 :p num5 :number6 :interface Interface7 :p num8 :number9 :function aliased10 param arg11 :ref Alias12 :return13 :ref Alias14 :function interfaced15 param arg16 :ref Interface17 :return18 :ref Interface
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type Alias = {
num: number;
};
interface Interface {
num: number;
}
function aliased(arg: Alias): Alias;
function interfaced(arg: Interface): Interface;
String Literal Types
1 +2 :type Easing3 :union4 :literal "ease-in"5 :literal "ease-out"6 :literal "ease-in-out"7 class UIElement8 m animate9 param dx10 :number11 param dy12 :number13 param easing14 :ref Easing15 if easing === "ease-in"16 else17 if easing === "ease-out"18 else19 if easing === "ease-in-out"20 else21 let button = new UIElement()22 _ button.animate(0, 0, "ease-in")23 _ button.animate(0, 0, "uneasy")24 :function createElement25 param tagName26 :literal "img"27 :return28 :ref HTMLImageElement29 :function createElement30 param tagName31 :literal "input"32 :return33 :ref HTMLInputElement34 function createElement35 param tagName36 :string37 :return38 :ref Element
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type Easing = "ease-in" | "ease-out" | "ease-in-out";
class UIElement {
animate(dx: number, dy: number, easing: Easing) {
if (easing === "ease-in") {
}
else {
if (easing === "ease-out") {
}
else {
if (easing === "ease-in-out") {
}
else {
}
}
}
}
}
let button = new UIElement();
button.animate(0, 0, "ease-in");
button.animate(0, 0, "uneasy");
function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
function createElement(tagName: string): Element {
}
Numeric Literal Types
1 +2 function rollDie3 :return4 :union5 :literal 16 :literal 27 :literal 38 :literal 49 :literal 510 :literal 611 function foo12 param x13 :number14 if x !== 1 || x !== 2
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function rollDie(): 1 | 2 | 3 | 4 | 5 | 6 {
}
function foo(x: number) {
if (x !== 1 || x !== 2) {
}
}
Enum Member Types
1 +2 :interface Square3 :p kind4 :literal "square"5 :p size6 :number7 :interface Rectangle8 :p kind9 :literal "rectangle"10 :p width11 :number12 :p height13 :number14 :interface Circle15 :p kind16 :literal "circle"17 :p radius18 :number19 :type Shape20 :union21 :ref Square22 :ref Rectangle23 :ref Circle24 function area25 param s26 :ref Shape27 switch s.kind28 case "square"29 return s.size * s.size30 case "rectangle"31 return s.height * s.width32 case "circle"33 return Math.PI * s.radius ** 2
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
interface Circle {
kind: "circle";
radius: number;
}
type Shape = Square | Rectangle | Circle;
function area(s: Shape) {
switch (s.kind) {
case "square": {
return s.size * s.size;
}
case "rectangle": {
return s.height * s.width;
}
case "circle": {
return Math.PI * s.radius ** 2;
}
}
}
Exhaustiveness checking
1 +2 :type Shape3 :union4 :ref Square5 :ref Rectangle6 :ref Circle7 :ref Triangle8 function area9 param s10 :ref Shape11 switch s.kind12 case "square"13 return s.size * s.size14 case "rectangle"15 return s.height * s.width16 case "circle"17 return Math.PI * s.radius ** 218 function area19 param s20 :ref Shape21 :return22 :number23 switch s.kind24 case "square"25 return s.size * s.size26 case "rectangle"27 return s.height * s.width28 case "circle"29 return Math.PI * s.radius ** 230 function assertNever31 param x32 :never33 :return34 :never35 throw new Error("Unexpected object: " + x)36 function area37 param s38 :ref Shape39 switch s.kind40 case "square"41 return s.size * s.size42 case "rectangle"43 return s.height * s.width44 case "circle"45 return Math.PI * s.radius ** 246 default47 return assertNever(s)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type Shape = Square | Rectangle | Circle | Triangle;
function area(s: Shape) {
switch (s.kind) {
case "square": {
return s.size * s.size;
}
case "rectangle": {
return s.height * s.width;
}
case "circle": {
return Math.PI * s.radius ** 2;
}
}
}
function area(s: Shape): number {
switch (s.kind) {
case "square": {
return s.size * s.size;
}
case "rectangle": {
return s.height * s.width;
}
case "circle": {
return Math.PI * s.radius ** 2;
}
}
}
function assertNever(x = never): never {
throw new Error("Unexpected object: " + x);
}
function area(s: Shape) {
switch (s.kind) {
case "square": {
return s.size * s.size;
}
case "rectangle": {
return s.height * s.width;
}
case "circle": {
return Math.PI * s.radius ** 2;
}
default: {
return assertNever(s);
}
}
}
Polymorphic this types
1 +2 class BasicCalculator3 ctor4 :public5 param value6 :number7 := 08 m currentValue9 :public10 return this.value11 m add12 :public13 param operand14 :number15 set this.value += operand16 return this17 m multiply18 :public19 param operand20 :number21 set this.value *= operand22 return this23 let v = new BasicCalculator(2).multiply(5).add(1).currentValue()24 class ScientificCalculator25 super BasicCalculator26 ctor27 :public28 param value = 029 _ super(value)30 m sin31 :public32 set this.value = Math.sin(this.value)33 return this34 let v = new ScientificCalculator(2).multiply(5).sin().add(1).currentValue()
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
class BasicCalculator {
public constructor(value: number = 0) {
}
public currentValue() {
return this.value;
}
public add(operand: number) {
this.value += operand;
return this;
}
public multiply(operand: number) {
this.value *= operand;
return this;
}
}
let v = new BasicCalculator(2).multiply(5).add(1).currentValue();
class ScientificCalculator extends BasicCalculator {
public constructor(value = 0) {
super(value);
}
public sin() {
this.value = Math.sin(this.value);
return this;
}
}
let v = new ScientificCalculator(2).multiply(5).sin().add(1).currentValue();
Index types
1 +2 function pluck3 param o4 param names5 return6 _ names.map7 =>8 param n9 + o[n]10 function pluck11 :< T12 :< K13 :keyof14 :ref T15 param o16 :ref T17 param names18 :[19 :ref K20 :return21 :[22 :[]23 :ref T24 :ref K25 return26 _ names.map27 =>28 param n29 + o[n]30 :interface Person31 :p name32 :string33 :p age34 :number35 let person36 :ref Person37 {38 @ name 'Jarid'39 @ age 3540 let strings41 :[42 :string43 _ pluck44 @ person45 [46 @ 'name'47 let personProps48 :keyof49 :ref Person50 _ pluck51 @ person52 [53 @ 'age'54 @ 'unknown'55 function getProperty56 :< T57 :< K58 :keyof59 :ref T60 param o61 :ref T62 param name63 :ref K64 :return65 :[]66 :ref T67 :ref K68 return o[name]69 let name70 :string71 _ getProperty(person, 'name')72 let age73 :number74 _ getProperty(person, 'age')75 let unknown = getProperty(person, 'unknown')76 :interface Map77 :< T78 :index79 :ref T80 param key81 :string82 let keys83 :keyof84 :ref Map85 :number86 let value87 :[]88 :ref Map89 :number90 :literal 'foo'
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function pluck(o, names) {
return names.map(n =>
o[n]
);
}
function pluck<T, K extends keyof T>(o: T, names: K[]): T[K][] {
return names.map(n =>
o[n]
);
}
interface Person {
name: string;
age: number;
}
let person: Person = {
name: 'Jarid',
age: 35
};
let strings: string[] = pluck(person, [
'name'
]);
let personProps: keyof Person;
pluck(person, [
'age',
'unknown'
])
function getProperty<T, K extends keyof T>(o: T, name: K): T[K] {
return o[name];
}
let name: string = getProperty(person, 'name');
let age: number = getProperty(person, 'age');
let unknown = getProperty(person, 'unknown');
interface Map<T> {
[key: string]: T;
}
let keys: keyof <Map>number;
let value = <Map>number['foo'];
Mapped types
1 +2 :interface PersonPartial3 :p name4 :optional5 :string6 :p age7 :optional8 :number9 :interface PersonReadonly10 :p name11 :string12 :p age13 :number14 :type Readonly15 :< T16 :mapped17 :< P18 :keyof19 :ref T20 :[]21 :ref T22 :ref P23 :type Partial24 :< T25 :mapped26 :optional27 :< P28 :keyof29 :ref T30 :[]31 :ref T32 :ref P33 :type PersonPartial34 :ref Partial35 :ref Person36 :type ReadonlyPerson37 :ref Readonly38 :ref Person39 :type Keys40 :union41 :literal 'option1'42 :literal 'option2'43 :type Flags44 :mapped45 :< K46 :ref Keys47 :boolean
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
interface PersonPartial {
name?: string;
age?: number;
}
interface PersonReadonly {
name: string;
age: number;
}
type Readonly<T> = [P in keyof T] : T[P];
type Partial<T> = [P in keyof T] : T[P];
type PersonPartial = <Partial>Person;
type ReadonlyPerson = <Readonly>Person;
type Keys = 'option1' | 'option2';
type Flags = [K in Keys] : boolean;
Mapped types 2
1 +2 :type Flags3 :{4 :p option15 :boolean6 :p option27 :boolean8 :type NullablePerson9 :mapped10 :< P11 :keyof12 :ref Person13 :union14 :[]15 :ref Person16 :ref P17 :null18 :type PartialPerson19 :mapped20 :optional21 :< P22 :keyof23 :ref Person24 :[]25 :ref Person26 :ref P27 :type Nullable28 :< T29 :mapped30 :< P31 :keyof32 :ref T33 :union34 :[]35 :ref T36 :ref P37 :null38 :type Partial39 :< T40 :mapped41 :optional42 :< P43 :keyof44 :ref T45 :[]46 :ref T47 :ref P48 :type Proxy49 :< T50 :{51 :m get52 :ref T53 :m set54 :void55 param value56 :ref T57 :type Proxify58 :< T59 :mapped60 :< P61 :keyof62 :ref T63 :ref Proxy64 :[]65 :ref T66 :ref P67 function proxify68 :< T69 param o70 :ref T71 :return72 :ref Proxify73 :ref T74 let proxyProps = proxify(props)75 :type Pick76 :< T77 :< K78 :keyof79 :ref T80 :mapped81 :< P82 :ref K83 :[]84 :ref T85 :ref P86 :type Record87 :< K88 :string89 :< T90 :mapped91 :< P92 :ref K93 :ref T94 :type ThreeStringProps95 :ref Record96 :union97 :literal 'prop1'98 :literal 'prop2'99 :literal 'prop3'100 :string
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type Flags = {
option1: boolean;
option2: boolean;
};
type NullablePerson = [P in keyof Person] : Person[P] | null;
type PartialPerson = [P in keyof Person] : Person[P];
type Nullable<T> = [P in keyof T] : T[P] | null;
type Partial<T> = [P in keyof T] : T[P];
type Proxy<T> = {
get(): T;
set(value: T): void;
};
type Proxify<T> = [P in keyof T] : <Proxy>T[P];
function proxify<T>(o: T): <Proxify>T {
}
let proxyProps = proxify(props);
type Pick<T, K extends keyof T> = [P in K] : T[P];
type Record<K extends string, T> = [P in K] : T;
type ThreeStringProps = Record;
Inference from mapped types
1 +2 function unproxify3 :< T4 param t5 :ref Proxify6 :param7 :ref T8 :return9 :ref T10 let result = {}11 for const k in t12 set result[k] = t[k].get()13 return result14 let originalProps = unproxify(proxyProps)
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function unproxify<T>(t: Proxify<T>): T {
let result = {};
for (const k in t) {
result[k] = t[k].get();
}
return result;
}
let originalProps = unproxify(proxyProps);
Conditional Types
1 +2 :function f3 :< T4 :boolean5 param x6 :ref T7 :return8 :iif9 :check10 :ref T11 :extends12 :literal true13 :then14 :string15 :else16 :number17 # Type is 'string | number18 let x = f(Math.random() < 0.5)19 # Another example would be the TypeName type alias, which uses nested conditional types:20 :type TypeName21 :< T22 :iif23 :check24 :ref T25 :extends26 :string27 :then28 :literal "string"29 :else30 :iif31 :check32 :ref T33 :extends34 :number35 :then36 :literal "number"37 :else38 :iif39 :check40 :ref T41 :extends42 :boolean43 :then44 :literal "boolean"45 :else46 :iif47 :check48 :ref T49 :extends50 :void51 :then52 :literal "undefined"53 :else54 :iif55 :check56 :ref T57 :extends58 :ref Function59 :then60 :literal "function"61 :else62 :literal "object"63 :type T064 :ref TypeName65 :param string66 # "string"67 :type T168 :ref TypeName69 :param70 :literal "a"71 # "string"72 :type T273 :ref TypeName74 :param75 :literal true76 # "boolean"77 :type T378 :ref TypeName79 :param80 :=>81 :void82 # "function"83 :type T484 :ref TypeName85 :param86 :[87 :string88 # "object"89 # But as an example of a place where conditonal types are deferred - where they stick around instead of picking a branch - would be in the following:90 :interface Foo91 :p propA92 :boolean93 :p propB94 :boolean95 :function f96 :< T97 param x98 :ref T99 :return100 :iif101 :check102 :ref T103 :extends104 :ref Foo105 :then106 :string107 :else108 :number109 function foo110 :< U111 param x112 :ref U113 # Has type 'U extends Foo ? string : number'114 let a = f(x)115 # This assignment is allowed though!116 let b117 :union118 :string119 :number120 := a
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
function f<T extends boolean>(x: T): T extends true ? string : number;
// Type is 'string | number
let x = f(Math.random() < 0.5);
// Another example would be the TypeName type alias, which uses nested conditional types:
type TypeName<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends void ? "undefined" : T extends Function ? "function" : "object";
type T0 = TypeName<string>;
// "string"
type T1 = TypeName<"a">;
// "string"
type T2 = TypeName<true>;
// "boolean"
type T3 = TypeName<() => void>;
// "function"
type T4 = TypeName<string[]>;
// "object"
// But as an example of a place where conditonal types are deferred - where they stick around instead of picking a branch - would be in the following:
interface Foo {
propA: boolean;
propB: boolean;
}
function f<T>(x: T): T extends Foo ? string : number;
// Has type 'U extends Foo ? string : number'
// This assignment is allowed though!
function foo<U>(x: U) {
let a = f(x);
let b: string | number = a;
}
Distributive conditional types
1 +2 :type T103 :ref TypeName4 :param5 :union6 :string7 :paren8 :=>9 :void10 :type T1211 :ref TypeName12 :param13 :union14 :string15 :[16 :string17 :void18 :type T1119 :ref TypeName20 :param21 :union22 :[23 :string24 :[25 :number26 #27 # In instantiations of a distributive conditional type T extends U ? X : Y, references to T within the conditional type are resolved28 # to individual constituents of the union type (i.e. T refers to the individual constituents after the conditional type is distributed29 # over the union type). Furthermore, references to T within X have an additional type parameter constraint U (i.e. T is considered30 # assignable to U within X).31 :type BoxedValue32 :< T33 :{34 :p value35 :ref T36 :type BoxedArray37 :< T38 :{39 :p array40 :[41 :ref T42 :type Boxed43 :< T44 :iif45 :check46 :ref T47 :extends48 :[49 :any50 :then51 :ref BoxedArray52 :param53 :[]54 :ref T55 :number56 :else57 :ref BoxedValue58 :param59 :ref T60 :type T2061 :ref Boxed62 :param string63 :type T2164 :ref Boxed65 :param66 :[67 :number68 :type T2269 :ref Boxed70 :param71 :union72 :string73 :[74 :number75 :type Diff76 :< T77 :< U78 :iif79 :check80 :ref T81 :extends82 :ref U83 :then84 :never85 :else86 :ref T87 :type Filter88 :< T89 :< U90 :iif91 :check92 :ref T93 :extends94 :ref U95 :then96 :ref T97 :else98 :never99 :type T30100 :ref Diff101 :param102 :union103 :literal "a"104 :literal "b"105 :literal "c"106 :literal "d"107 :param108 :union109 :literal "a"110 :literal "c"111 :literal "f"112 :type T31113 :ref Filter114 :param115 :union116 :literal "a"117 :literal "b"118 :literal "c"119 :literal "d"120 :param121 :union122 :literal "a"123 :literal "c"124 :literal "f"125 :type T32126 :ref Diff127 :param128 :union129 :string130 :number131 :paren132 :=>133 :void134 :param135 :ref Function136 :type T33137 :ref Filter138 :param139 :union140 :string141 :number142 :paren143 :=>144 :void145 :param146 :ref Function147 :type NonNullable148 :< T149 :ref Diff150 :param151 :ref T152 :param153 :union154 :null155 :void156 :type T34157 :ref NonNullable158 :param159 :union160 :string161 :number162 :void163 :type T35164 :ref NonNullable165 :param166 :union167 :string168 :[169 :string170 :null171 :void172 function f1173 :< T174 param x175 :ref T176 param y177 :ref NonNullable178 :param179 :ref T180 set x = y181 set y = x182 function f2183 :< T184 :union185 :string186 :void187 param x188 :ref T189 param y190 :ref NonNullable191 :param192 :ref T193 set x = y194 set y = x195 let s1196 :string197 := x198 let s2199 :string200 := y
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type T10 = TypeName<string | (() => void)>;
type T12 = TypeName<string | string[] | void>;
type T11 = TypeName<string[] | number[]>;
//
type BoxedValue<T> = {
value: T;
};
type BoxedArray<T> = {
array: T[];
};
type Boxed<T> = T extends any[] ? BoxedArray<T[number]> : BoxedValue<T>;
type T20 = Boxed<string>;
type T21 = Boxed<number[]>;
type T22 = Boxed<string | number[]>;
type Diff<T, U> = T extends U ? never : T;
type Filter<T, U> = T extends U ? T : never;
type T30 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">;
type T31 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">;
type T32 = Diff<string | number | (() => void), Function>;
type T33 = Filter<string | number | (() => void), Function>;
type NonNullable<T> = Diff<T, null | void>;
type T34 = NonNullable<string | number | void>;
type T35 = NonNullable<string | string[] | null | void>;
function f1<T>(x: T, y: NonNullable<T>) {
x = y;
y = x;
}
function f2<T extends string | void>(x: T, y: NonNullable<T>) {
x = y;
y = x;
let s1: string = x;
let s2: string = y;
}
Conditional types combined with mapped types:
1 +2 :type FunctionPropertyNames3 :< T4 :[]5 :mapped6 :< K7 :keyof8 :ref T9 :iif10 :check11 :[]12 :ref T13 :ref K14 :extends15 :ref Function16 :then17 :ref K18 :else19 :never20 :keyof21 :ref T22 :type FunctionProperties23 :< T24 :ref Pick25 :param26 :ref T27 :param28 :ref FunctionPropertyNames29 :param30 :ref T31 :type NonFunctionPropertyNames32 :< T33 :[]34 :mapped35 :< K36 :keyof37 :ref T38 :iif39 :check40 :[]41 :ref T42 :ref K43 :extends44 :ref Function45 :then46 :never47 :else48 :ref K49 :keyof50 :ref T51 :type NonFunctionProperties52 :< T53 :ref Pick54 :param55 :ref T56 :param57 :ref NonFunctionPropertyNames58 :param59 :ref T60 :interface Part61 :p id62 :number63 :p name64 :string65 :p subparts66 :[67 :ref Part68 :m updatePart69 :void70 param newName71 :string72 :type T4073 :ref FunctionPropertyNames74 :param75 :ref Part76 :type T4177 :ref NonFunctionPropertyNames78 :param79 :ref Part80 :type T4281 :ref FunctionProperties82 :param83 :ref Part84 :type T4385 :ref NonFunctionProperties86 :param87 :ref Part88 :type ElementType89 :< T90 :iif91 :check92 :ref T93 :extends94 :[95 :any96 :then97 :ref ElementType98 :param99 :[]100 :ref T101 :number102 :else103 :ref T
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type FunctionPropertyNames<T> = {[K in keyof T] : T[K] extends Function ? K : never}[ keyof T];
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
type NonFunctionPropertyNames<T> = {[K in keyof T] : T[K] extends Function ? never : K}[ keyof T];
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
interface Part {
id: number;
name: string;
subparts: Part[];
updatePart(newName: string): void;
}
type T40 = FunctionPropertyNames<Part>;
type T41 = NonFunctionPropertyNames<Part>;
type T42 = FunctionProperties<Part>;
type T43 = NonFunctionProperties<Part>;
type ElementType<T> = T extends any[] ? ElementType<T[number]> : T;
Type inference in conditional types
1 +2 :type ReturnType3 :< T4 :iif5 :check6 :ref T7 :extends8 :=>9 :infer10 :< R11 param ...args12 :[13 :any14 :then15 :ref R16 :else17 :any18 :type Unpacked19 :< T20 :iif21 :check22 :ref T23 :extends24 :[25 :paren26 :infer27 :< U28 :then29 :ref U30 :else31 :iif32 :check33 :ref T34 :extends35 :=>36 :infer37 :< U38 param ...args39 :[40 :any41 :then42 :ref U43 :else44 :iif45 :check46 :ref T47 :extends48 :ref Promise49 :param50 :infer51 :< U52 :then53 :ref U54 :else55 :ref T56 :type T057 :ref Unpacked58 :param string59 :type T160 :ref Unpacked61 :param62 :[63 :string64 :type T265 :ref Unpacked66 :param67 :=>68 :string69 :type T370 :ref Unpacked71 :param72 :ref Promise73 :param string74 :type T475 :ref Unpacked76 :param77 :[78 :ref Promise79 :param string80 :type T581 :ref Unpacked82 :param83 :ref Unpacked84 :param85 :[86 :ref Promise87 :param string88 :type Foo89 :< T90 :iif91 :check92 :ref T93 :extends94 :{95 :p a96 :infer97 :< U98 :p b99 :infer100 :< U101 :then102 :ref U103 :else104 :never105 :type T10106 :ref Foo107 :param108 :{109 :p a110 :string111 :p b112 :string113 :type T11114 :ref Foo115 :param116 :{117 :p a118 :string119 :p b120 :number121 :type Bar122 :< T123 :iif124 :check125 :ref T126 :extends127 :{128 :p a129 :=>130 :void131 param x132 :infer133 :< U134 :p b135 :=>136 :void137 param x138 :infer139 :< U140 :then141 :ref U142 :else143 :never144 :type T20145 :ref Bar146 :param147 :{148 :p a149 :=>150 :void151 param x152 :string153 :p b154 :=>155 :void156 param x157 :string158 :type T21159 :ref Bar160 :param161 :{162 :p a163 :=>164 :void165 param x166 :string167 :p b168 :=>169 :void170 param x171 :number172 :function foo173 param x174 :string175 :return176 :number177 :function foo178 param x179 :number180 :return181 :string182 :function foo183 param x184 :union185 :string186 :number187 :return188 :union189 :string190 :number191 :type T30192 :ref ReturnType193 :param194 :typeof foo195 :type ReturnType196 :< T197 :=>198 :infer199 :< R200 param ...args201 :[202 :any203 :ref R204 :type AnyFunction205 :=>206 :any207 param ...args208 :[209 :any210 :type ReturnType211 :< T212 :ref AnyFunction213 :iif214 :check215 :ref T216 :extends217 :=>218 :infer219 :< R220 param ...args221 :[222 :any223 :then224 :ref R225 :else226 :any
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
type Unpacked<T> = T extends ( infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise< infer U> ? U : T;
type T0 = Unpacked<string>;
type T1 = Unpacked<string[]>;
type T2 = Unpacked<() => string>;
type T3 = Unpacked<Promise<string>>;
type T4 = Unpacked<Promise<string>[]>;
type T5 = Unpacked<Unpacked<Promise<string>[]>>;
type Foo<T> = T extends {
a: infer U;
b: infer U;
} ? U : never;
type T10 = Foo<{
a: string;
b: string;
}>;
type T11 = Foo<{
a: string;
b: number;
}>;
type Bar<T> = T extends {
a: (x = infer U) => void;
b: (x = infer U) => void;
} ? U : never;
type T20 = Bar<{
a: (x: string) => void;
b: (x: string) => void;
}>;
type T21 = Bar<{
a: (x: string) => void;
b: (x: number) => void;
}>;
function foo(x: string): number;
function foo(x: number): string;
function foo(x: string | number): string | number;
type T30 = ReturnType<typeof foo>;
type ReturnType<T extends (...args: any[]) => infer R> = R;
type AnyFunction = (...args: any[]) => any;
type ReturnType<T extends AnyFunction> = T extends (...args: any[]) => infer R ? R : any;
Predefined conditional types
1 +2 :type T003 :ref Exclude4 :param5 :union6 :literal "a"7 :literal "b"8 :literal "c"9 :literal "d"10 :param11 :union12 :literal "a"13 :literal "c"14 :literal "f"15 :type T0116 :ref Extract17 :param18 :union19 :literal "a"20 :literal "b"21 :literal "c"22 :literal "d"23 :param24 :union25 :literal "a"26 :literal "c"27 :literal "f"28 :type T0229 :ref Exclude30 :param31 :union32 :string33 :number34 :paren35 :=>36 :void37 :param38 :ref Function39 :type T0340 :ref Extract41 :param42 :union43 :string44 :number45 :paren46 :=>47 :void48 :param49 :ref Function50 :type T0451 :ref NonNullable52 :param53 :union54 :string55 :number56 :void57 :type T0558 :ref NonNullable59 :param60 :union61 :paren62 :=>63 :string64 :[65 :string66 :null67 :void68 function f169 param s70 :string71 return72 {73 @ a 174 @ b s75 class C76 p x77 := 078 p y79 := 080 :type T1081 :ref ReturnType82 :param83 :=>84 :string85 :type T1186 :ref ReturnType87 :param88 :=>89 :void90 param s91 :string92 :type T1293 :ref ReturnType94 :param95 :paren96 :=>97 :< T98 :ref T99 :type T13100 :ref ReturnType101 :param102 :paren103 :=>104 :< T105 :ref U106 :< U107 :[108 :number109 :ref T110 :type T14111 :ref ReturnType112 :param113 :typeof f1114 :type T15115 :ref ReturnType116 :param any117 :type T16118 :ref ReturnType119 :param never120 :type T17121 :ref ReturnType122 :param string123 :type T18124 :ref ReturnType125 :param126 :ref Function127 :type T20128 :ref InstanceType129 :param130 :typeof C131 :type T21132 :ref InstanceType133 :param any134 :type T22135 :ref InstanceType136 :param never137 :type T23138 :ref InstanceType139 :param string140 :type T24141 :ref InstanceType142 :param143 :ref Function144 # Error
/*
artifact generator: /app/node_modules/@wizzi/plugin.ts/lib/artifacts/ts/module/gen/main.js
package: wizzi.plugin.ts@
primary source IttfDocument: json:/index.ts.ittf
utc time: Tue, 06 May 2025 04:46:20 GMT
*/
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">;
type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">;
type T02 = Exclude<string | number | (() => void), Function>;
type T03 = Extract<string | number | (() => void), Function>;
type T04 = NonNullable<string | number | void>;
type T05 = NonNullable<(() => string) | string[] | null | void>;
function f1(s: string) {
return {
a: 1,
b: s
};
}
class C {
x = 0;
y = 0;
}
type T10 = ReturnType<() => string>;
type T11 = ReturnType<(s: string) => void>;
type T12 = ReturnType<(<T>() => T)>;
type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>;
type T14 = ReturnType<typeof f1>;
type T15 = ReturnType<any>;
type T16 = ReturnType<never>;
type T17 = ReturnType<string>;
type T18 = ReturnType<Function>;
type T20 = InstanceType<typeof C>;
type T21 = InstanceType<any>;
type T22 = InstanceType<never>;
type T23 = InstanceType<string>;
type T24 = InstanceType<Function>;
// Error