Импорт типов.d.ts из внешнего проекта

Скажем, у меня есть проект 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"

но это не похоже на работу.

Как правильно импортировать эти типы?

1 ответ

Ваш проект x не объявляет типы отдельно от значений. Таким образом, чтобы получить доступ к типу, вам нужно использовать typeof:

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

// or
import { makePathExecutable } from 'x'
type MakePathExecutable = typeof makePathExecutable
Другие вопросы по тегам