[英]Import .d.ts types from external project
假設我在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"
但這似乎並不奏效。
導入這些類型的正確方法是什么?
您的項目x
不會將值分別聲明為類型。 因此,要訪問類型,您需要使用typeof
:
import * as X from 'x'
type MakePathExecutable = typeof X.makePathExecutable
// or
import { makePathExecutable } from 'x'
type MakePathExecutable = typeof makePathExecutable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.