无法在离子 2 中从 JS 切换到 TS
Unable to switch from JS to TS in ionic 2
我更改了我的应用程序文件的文件扩展名,包括应用程序/应用程序.js
Error: Cannot find module 'app/app.js' from 'app_folder'
它没有告诉我应该查看哪个文件来修复错误。
我试着用git grep
查找并阅读了一些关于 Angular2 的入口点以找出它的加载位置,但还没有运气。
在 Ionic2 项目中使用 TypeScript 不仅仅是切换文件的扩展名 ;-)
您需要将 TypeScript 编译器与 gulp-tsc'
插件集成到 Gulp 中:
var typescript = require('gulp-tsc');
(...)
gulp.task('compile', function() {
gulp.src(paths.src)
.pipe(typescript({
emitError: false
}))
.pipe(gulp.dest('www/js/'))
});
此页面可以帮助您:
- https://github.com/driftyco/ionic-typescript-example
Thierry Templier让我走上了正确的轨道,这就是答案。
文档,以防其他人想知道。
Ionic2与ionic1不同,现在基本上使用browserify。要从 ES6 切换到 TS,您需要为您的项目设置 typscirpt 并像这样设置依赖项:
- 在
gulpfile.js
改变var buildBrowserify = require('ionic-gulp-browserify-es2015');
对于var buildBrowserify = require('ionic-gulp-browserify-typescript');
- 在
package.json
改变ionic-gulp-browserify-es2015": "^1.0.2"
对于"ionic-gulp-browserify-typescript": "^1.0.0"
-
安装打字稿
3.1
npm install typings --global
3.2
tsd query node --action install --save
-
确保您有文件
your_app/typings/main.d.ts
内容:/// <reference path="main/ambient/es6-shim/index.d.ts" />
-
最后是
tsconfig.json
文件tsconfig{ "compilerOptions": { "target": "es5", "module": "commonjs", "emitDecoratorMetadata": true, "experimentalDecorators": true }, "filesGlob": [ "**/*.ts", "!node_modules/**/*" ], "exclude": [ "node_modules", "typings/main", "typings/main.d.ts" ], "compileOnSave": false, "atom": { "rewriteTsconfig": false } }
- 无法在离子 2 中从 JS 切换到 TS
- TypeScript d.ts 和 .js 一致性
- index.js没有做index.ts做的事
- TS/JS 箭头函数更改“this”的值
- 使用私有实例方法实现 TS/JS 装饰器
- 将一个typescript库绑定到一个.js文件和一个.d.ts
- 如何从以前的typescript(.ts)文件中删除已编译的JS文件
- 配置WebStorm/PhpStorm将.ts文件编译为.js文件;js”;文件夹
- Node.js automapper ts包未映射嵌套对象/属性
- Karma-coverage在JS文件中检查测试覆盖率,而不是Angular 2中的TS文件
- Systemjs and tsc setup - *.ts.js 404 (Not Found) Error
- 生成单独的.js文件,但合并.d.在Visual Studio中使用Typescript编写ts文件
- 我应该上传ts (typescript)文件或生成的js文件或两者
- Karma + JSPM + Typescript - not found '.ts.js'
- 从js文件生成.d.ts的过程
- 如何更改选择组件'使用Knockout从JS(TS)中获取s值
- 正在绑定我的JS/TS项目反模式
- 正在为detect-element-resize.js编写TypeScript定义文件(.d.ts)
- 使用PHPStorm在TypeScript项目中包含*.d.ts文件(以及相应的JS)
- 告诉Chrome调试js而不是ts