第 3 方应用级别的临时类型

3rd party app level temporary typings

关于如何让自定义类型在 anuglar2 quickstart 项目中工作的一些事情。

我正在使用 outlayerhttps://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 中并不理想,原因显而易见。无需分叉库即可处理此问题的更好方法是什么?更妙的是,我怎样才能在应用程序级别进行 simple/quick 打字,这样我就不必担心立即写出整个内容?例如,如果我现在尝试使用 data 函数,我会看到 Property 'data' does not exist on type 'typeof Outlayer'

总而言之,只需要能够编写自定义应用程序级别的类型,既没有所有好东西,也没有发出所有错误。一种临时打字。

谢谢!

这是您需要做的:

  1. 在某处创建文件(例如custom-typings/outlayer.d.ts
  2. 将其设为脚本文件(全局类型):

    declare module 'outlayer' {
      function create(str: string): any;
    }
    
  3. 安装 typings install file:custom-typings/outlayer.d.ts --global

看看有没有帮助。

编辑:更新了上面的第 3 步以添加 --global