用tsc编译ts
源代码 /*因为编译后的代码包含es6新增api,比如下边的includes,有浏览器可能不支持,故而需要引入垫片 这里可以选择core-js,也可以ts-polyfill,目的都是一样的*/ import 'core-js'; //具体目标 class Utils { protected cname:string = 'Utils'; public test(): void{ [1,2,3].includes(2) } } (window as any).subject = new Utils(); //方便页面使用 使用tsc编译 tsconfig.json配置如下 { "compilerOptions": { "target": "es5", /* 编译的目标是什么版本的 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs",/* 编译后模块化类型 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": [ //编译过程中需要引入的库文件的列表。 "es5", "es2016.array.include", "dom