2017-10-01 59 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