将自定义类型文件添加到Angular CLI [英] Add custom typings files to 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
- 为文件编写类型定义;
- 将JS文件及其类型定义(.d.ts)导入到应用程序中
我的问题是如何将自定义类型定义文件添加到我的Angular CLI应用程序中? (我知道JS文件可以从.angular-cli.json文件中的"scripts": []
添加,对吧?)
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.
推荐答案
您在此处有几个选择:
-
在新建应用程序的
src
目录中,有一个文件typings.d.ts
,您可以使用该文件引用团队成员的.d.ts
文件,该文件将在整个应用程序中公开这些类型.
In the
src
dir for newly created applications there is a filetypings.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屋!