angular7 - Angular 7 中的 declarations.d.ts

标签 angular7 typescript-typings

几天前,我切换到 Angular 7,但无法找到 declarations.d.ts。

在 Angular 2 和 4 中,我使用 declarations.d.ts 来定义 JQUERY 和其他类型的类型 -

interface JQuery {
  datepicker(options: any): JQuery;
  modal(options: any): JQuery;
}

在 Angular 7 中在哪里定义未知元素接口(interface)?

注意:我使用 Angular CLI 生成项目。

最佳答案

/src 文件夹中使用 typings.d.ts

更多信息在这里:TypeScript Configuration

更新

实现目标的更好方法是使用 jQuery's typings . 请务必添加:

"typeRoots": [
  "node_modules/@types"
],

到您的 tsconfig.json 以便 typescript 知道在哪里搜索类型。 大多数著名的库都会有他们的 typings 包,所以首先尝试从 npm 获取它,如果找不到,那么您总是可以在 typings.d.ts

中定义它们

关于angular7 - Angular 7 中的 declarations.d.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54995976/

相关文章:

angular7 - 无法加载 server.component.html

angular - 带有多个选项的 mat-select 中的样式复选框

css - 使用转到下一个选项卡时,按钮未使用 Angular Material 出现

Typescript Private or protected member 'something' 无法在类型参数上访问

reactjs - this.onPressItem 不是 map 中的函数

angular - 将 "exceljs"lib 导入 Angular 最佳方法是什么

javascript - 使用 angular-router 在页面中导航 View

cordova - typescript 错误 : Cannot find name 'cordova'

reactjs - 为 typescript 的 npm react 模块定义类型

node.js - 如何在 Typescript 中将属性重写为不可为空