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

查看:57
本文介绍了将自定义类型文件添加到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应用程序中? (我知道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.

推荐答案

您在此处有几个选择:

  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天全站免登陆