资源加载中... loading...

TypeScript 演示

Author: 发明者量化, Date: 2023-03-21 16:34:56
Tags:

平台加入原生TypeScript支持, 只需要在源码开头加入 (策略语言类型还是选JavaScript)

// @ts-check

就可以自动识别为TypeScript


// @ts-check

class Greeter {
    greeting: string;

    constructor(message: string) {
        this.greeting = message;
    }

    greet() {
        return "Hello, " + this.greeting;
    }
}


function peopleName(firstName: string, ...restOfname: string[]) {
    return firstName + " " + restOfname.join(" ");
}


function main() {
    let greeter = new Greeter("world");
    Log(greeter.greet());

    
    Log(peopleName('xiaochuan', 'xiaoming', 'xiaohong'))
}



More