将自定义类型文件添加到 Angular CLI [英] Add custom typings files to Angular CLI

查看:31
本文介绍了将自定义类型文件添加到 Angular CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 Angular CLI 框架的 SPA 和一个由团队成员编写的 Javascript 库.我需要将此 JS 文件注入到应用程序中.我的想法是

I have a SPA with Angular CLI framework and a Javascript library written by a team member. I need to inject this JS file into the app. My thought is

  1. 为文件编写类型定义;
  2. 将 JS 文件及其类型定义 (.d.ts) 导入应用程序

我的问题是如何将自定义类型定义文件添加到我的 Angular CLI 应用程序中?(我知道可以从 .angular-cli.json 文件中的 "scripts": [] 添加 JS 文件,对吗?)

My question is how to add the custom type definition file into my Angular CLI app? (I know the JS file can be added from "scripts": [] in .angular-cli.json file, right?)

我看到了一些将外部 js 库添加到 angular-cli 的帖子,但它们似乎都在 npm 上,这显然对我不起作用.

I saw some posts for adding external js library to angular-cli, but they all seem on npm which doesn't work for me apparently.

推荐答案

这里有几个选项:

  1. 在新创建的应用程序的 src 目录中有一个文件 typings.d.ts,您可以使用它来引用您团队成员的 .d.ts 文件,它将在整个应用程序中公开这些类型.

  1. In the src dir for newly created applications there is a file typings.d.ts which you can use reference your team member's .d.ts file which will expose those types throughout your application.

tsconfig.json 文件中,您可以将包所在的 node_modules 文件夹的路径添加到 typeRoots 数组这将使这些输入也可用.

In the tsconfig.json file you can add the path to the node_modules folder where this package lives to the typeRoots array which will make those typing available too.

这篇关于将自定义类型文件添加到 Angular CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆