Way*_*oss 3 javascript intellisense typescript visual-studio-code typescript-typings
我想创建一个index.d.ts文件,该文件引用来自称为的流行NPM包中的某些类型redux。
(在我index.d.ts文件的顶部)
/// <reference path="../../../node_modules/redux/index.d.ts" />这行不通。我怀疑这是因为redux/index.d.ts文件根本没有声明名称空间。当我编辑redux/index.d.ts文件并用包裹所有内容时declare namespace Redux { ... },一切正常。我在redux@^4.0.0。
/// <reference types="redux" />除非我安装了NPM软件包@types/redux/@3.6.31,否则它将无法工作,该软件包的类型过时且与发布的类型不匹配。最新版本的@types/redux软件包只是一个已弃用的占位符,该占位符表示要使用正式的redux软件包类型(不起作用)。
import { Middleware } from "redux";当我将import上面显示的语句放入index.d.ts文件中时,文件中的每个声明都中断了(即,我依赖于自己的index.d.ts文件进行类型定义的每个其他位置都停止从中读取任何类型。)文件import类型的语句d.ts使Typescript将该文件视为模块,而不是定义文件。
@types/redux@3.6.31而不是最新的不推荐使用的占位符版本@types/redux。node_modules/redux/index.d.ts以将所有内容包装在名称空间中,例如declare namespace Redux { ... }。我的项目使用create-react-appv2作为JavaScript项目进行了引导。我只是使用d.ts文件来记录一些接口。我的编辑器是VSCode最新/稳定的。
Since typescript 2.9 (see section on import types) you can use import() to use the type definition files without actually importing the module itself. For example this definition will work using the Action type from the redux package:
declare function createCustomAction(): import("redux").Action
Run Code Online (Sandbox Code Playgroud)
No need to reference anything at the top with the triple slash directive.
| 归档时间: |
|
| 查看次数: |
563 次 |
| 最近记录: |