我正在努力得到Vue.js 2.0打字在Visual Studio中使用TypeScript.之前,我使用了these typings from DefinitelyTyped,但它们是用于Vue的.js 1.0,因此不匹配.然而,它们确实工作得很好,让我使用Vue
型.
此后,我开始使用Vue附带的键入文件.js发布(here).我已经将它们包含在我的~/Scripts/typings/vue
文件夹中的项目中,但我的项目不理解它们.
据我所知,这些打字文件可能是通过导入/导出来使用的?我使用的其他打字文件都不是这样工作的,所以我不确定如何正确地实现打字,使它们在我的项目中全局可用.
我有一个示例解决方案,它展示了我try 过的一个例子——download here from my github repo.
以下是我的Scripts
文件夹的 struct :
_references.d.ts个目录
/// <reference path="typings/vue/index.d.ts" />
vue_test.ts个目录
namespace Test
{
export class MyClass
{
public initialize()
{
var component = this.getComponent();
}
private getComponent(): Vue.Component
{
return Vue.component("test", {
template: "<div></div>",
props: ["test"],
methods: {
onClick: () =>
{
}
}
});
}
}
}
我希望我能够访问Vue.Component
个名称空间和typings/vue/index.d.ts
中声明的其他名称空间,但情况似乎并非如此.
我try 将导出的类导入到global
中,如下所示:
import * as _Vue from "./index";
declare global
{
export class Vue extends _Vue
{
}
}
然而,这只允许我访问根Vue
类,因此我无法执行诸如将Vue.Component
指定为类型或Vue
之外的任何其他名称空间之类的操作.
Other information:
UPDATE after suggestions from @unional
没有更多的参考资料.d、 ts,使用tsconfig.而是json.Tconfig.json文件包含以下内容:
{
"compilerOptions": {
"sourceMap": true
},
"include": [
"../../**/*.ts"
]
}
以上都是进口商品.项目中的ts文件.~/Scripts/typings/custom-typings/vue.d.ts
文件包含以下内容:
export * from "vue"
export as namespace Vue
VisualStudio告诉我Cannot find module 'vue'
,所以我的打字仍然不起作用,尽管Tconfig.json文件可以工作(我添加了jQuery类型以验证这一点).
下面是更新解决方案的链接,显示了新问题:[link]