假设我的package.json中包含以下项目X:
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
我想将index.d.ts文件中的所有类型导入另一个项目。
index.d.ts文件如下所示:
export declare const makePathExecutable: (runPath: string, cb: Function) => void;
export declare const checkForEquality: (arr1: string[], arr2: string[]) => boolean;
export declare const arrayHasDuplicates: (a: any[]) => boolean;
export declare const isStringWithPositiveLn: (s: string) => boolean;
export declare const findNearestRunAndTransform: (root: string, pth: string, cb: Function) => any;
export declare const findSumanMarkers: (types: string[], root: string, files: string[], cb: IMapCallback) => void;
export declare const isObject: (v: any) => boolean;
在我的其他项目中,我尝试导入这些类型:
import * as X from "x"
但这似乎并没有起作用。
导入这些类型的正确方法是什么?
答案 0 :(得分:0)
您的项目x
未与值分开声明类型。因此,要访问该类型,您需要使用typeof
:
import * as X from 'x'
type MakePathExecutable = typeof X.makePathExecutable
// or
import { makePathExecutable } from 'x'
type MakePathExecutable = typeof makePathExecutable