我在 ember 中有一个现有项目。到目前为止,我在项目中使用了 JavaScript。但是,我想在同一个项目中使用 TypeScript,但保留现有代码。无论我现在写什么,我都想在 TS 中完成。 什么是最佳实践,更重要的是,我是否必须设置项目以促进它?
谢谢!
最佳答案
是的,您可以保持现有的 js
文件不变,并开始将新的 ts
文件添加到您现有的项目中:
yarn add typescript -D
ember install ember-cli-typescript@latest
之后,您的应用应该会照常运行。现在,如果您希望 Typescript 处理它们,您可以将单个文件的扩展名从 js
更改为 ts
。或者,简单地添加带有 ts
扩展名的新文件。
该插件还将为新对象创建 ts
文件,例如:
ember g helper foobar
installing helper
create app/helpers/foobar.ts
installing helper-test
create tests/integration/helpers/foobar-test.ts
关于typescript - 如何在 Ember.js 中使用 TypeScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43393808/