2017-10-01 47 views
0

类型说我有一个在它的package.json以下项目X:进口.d.ts从外部项目

"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

'进口*为“×” X'似乎要导入的.js文件,但我只是想导入的类型 –

回答

1

您的项目x未声明与这些值分开的类型。因此,要访问的类型,你需要使用typeof

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

// or 
import { makePathExecutable } from 'x' 
type MakePathExecutable = typeof makePathExecutable