0

假设我有一个项目 X,其 package.json 中有以下内容:

  "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"

但这似乎并不奏效。

导入这些类型的正确方法是什么?

4

1 回答 1

0

Your project x does not declare the types separately from the values. So to access the type, you need to use typeof:

import * as X from 'x'
type MakePathExecutable = typeof X.makePathExecutable

// or
import { makePathExecutable } from 'x'
type MakePathExecutable = typeof makePathExecutable
于 2017-10-01T07:05:45.560 回答