关于如何获取自定义类型以在anuglar2快速入门项目中工作的一些事情。
我以outlayer
库https://github.com/metafizzy/outlayer为例。
我已配置systemjs
为加载依赖项。它可用并且可以使用,import * as outlayer from "outlayer";
但是我仍然收到编译错误Cannot find module 'outlayer'.
为了解决这个问题,已经outlayer.d.ts
在node_modules/outlayer
目录中直接添加了类型文件,并将其更新package.json
为包括"typings": "./outlayer.d.ts",
。
//outlayer.d.ts
declare module Outlayer {
function create(str:string):any;
}
export = Outlayer;
由于明显的原因,将此文件直接添加到node_module并不理想。无需派生库来处理此问题的更好方法是什么?更好的是,如何在应用程序级别上进行简单/快速的输入,这样我就不必担心立即写出整个内容?例如,如果我现在尝试使用该data
功能,我会看到Property 'data' does not exist on type 'typeof Outlayer'
总而言之,只需要能够编写一个自定义的应用程序级别类型,该类型不具有所有优点,但也不能避免所有错误。一种临时打字方式。
谢谢!
这是您需要做的:
custom-typings/outlayer.d.ts
)下创建文件使其成为脚本文件(全局类型):
declare module 'outlayer' {
function create(str: string): any;
}
与安装 typings install file:custom-typings/outlayer.d.ts --global
看看是否有帮助。
编辑:更新以上第3步以添加 --global
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句