TypeScript + HTML 多个JavaScript入门

 例子下载

需要require.js支持

index1.html

<script data-main="bin/index.js" src="require.js"></script>

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "umd",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "outDir": "bin",                        /* Redirect output structure to the directory. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "sourceMap": true,
    //"baseUrl": "ts",  //不要这个设置,会导致自动生成的import语句缺少./部分,运行时报找不到模块出错
    //"esModuleInterop": true,
    //"moduleResolution": "node"
    }
}

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build ts",
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.json

{
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome",
            //"url": "http://127.0.0.1:8000/index1.html",
            "url": "${workspaceFolder}/index1.html",
            "webRoot": "${workspaceFolder}"
        },
        // {
        //     "type": "node",
        //     "request": "launch",
        //     "name": "Launch Program",
        //     "program": "${workspaceFolder}\\bin\\index.js",
        //     //"preLaunchTask": "build ts",
        //     //"cwd": "${workspaceFolder}/./bin",  //修改执行node index.js 的路径
        //     "console": "internalConsole",       //输出到 DEBUG CONSOLE (默认值)
        //     "internalConsoleOptions": "openOnSessionStart",  //每次运行自动转到 DEBUG CONSOLE 以显示输出内容
        //     "outFiles": [
        //         "${workspaceFolder}/**/*.js"
        //     ]
        // }
    ]
}

index.ts

import { M3 } from "./m3";
import { M2 } from "./m2";

let r1 = M1.MM1.C1.Add1(10, 20);
document.write("r1, " + r1);
//let r2 = M2.C2.Add2(10, 20);  //C2没有export所以编译不了
let r3 = M3.C3.Add3(10, 20);
document.write("<br>r3, " + r3);

m1.ts

module M1.MM1
{
    export class C1
    {
        public static Add1(a:number, b:number)
        {
            return 100 * (a + b);
        }
    }
}

m2.ts

export module M2
{
    class C2  //类不export就访问不到
    {
        public static Add2(a:number, b:number)
        {
            return 200 * (a + b);
        }
    }
}

m3.ts

export module M3
{
    export class C3
    {
        public static Add3(a:number, b:number)
        {
            return 300 * (a + b);
        }
    }
}

 

转载于:https://www.cnblogs.com/nuets/p/10133430.html

什么是TypeScriptTypeScriptJavaScript的加强版,它给JavaScript添加了可选的静态类型和基于类的面向对象编程,它拓展了JavaScript的语法。不过,你不必担心TypeScript跟浏览器不兼容,因为在编译时,它产生的都是JavaScript代码。为什么要学TypeScritpt?TypeScript是一门很有前景和钱景的语言;它能大幅的提高工作效率,并且减少错误;这堂课我们能学到什么?随着前端行业越来越受到重视,前端的逻辑也越来越复杂,对前端从业者的职业要求也越来越高,Vue、Angular、React和一些新的框架层出不穷,而作为Angular等框架的推荐语言TypeScript也在市场中得到了认可和追捧,不管是前端、还是游戏引擎、以及一些大型项目开发都中开始展露头角。但是这方面学习资源相对较少。课程特点:本堂课程通过深入浅出的讲解,幽默风趣的风格; 让大家在3个小时的课程中能够掌握大部分TypeScript的核心知识; 同时能够使用TypeScript进行React等框架的项目开发; 为大家的学习和在工作中使用TypeScript打下坚实的基础。课程大纲:1.TS的初步配置2.TS 数据类型 any 枚举3.函数的参数和返回值类型4.类非常重要 非常重要5.静态类属性和方法 Math6.泛型7.模块化 systemjs8.项目TS+react+webpack结合的工作流应类型管理 js->tsx 2.0如何用TS开发react->TSX(难点->官网 项目)工作流 package.json -> npm start npm run build 适用人群:1.Typescript零基础想掌握ts正确学习姿势和入门的初学者2.经验丰富的jser想拓宽自己知识掌握ES6和ES7新功能的从业者3.想在工作和项目中使用ts结合VAR框架的人员4.有志于成为全栈开发人员却苦于无法入门后端和跟后端沟通不畅的开发者5.想深入了解和使用angular的人员
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值