如何导入模块的Typescript类型以在我自己的类型定义中使用?

问题描述

我想为options对象编写一个类型,该对象本身包括导入模块中的类型,在这种情况下为Moment.js:

import moment from 'moment'

export type myOptions = {
 // ...
 myDate: Moment;
}

export function myFunction(options: myOptions) {
 // ...
}

这不起作用,似乎类型'Moment'并未与库'moment'一起导入:

$ npx tsc
example.ts:5:10 - error TS2304: Cannot find name 'Moment'.

5  myDate: Moment;
           ~~~~~~


Found 1 error.

是否可以通过这种方式在其他库的类型上进行构建?

解决方法

嗯,好吧,这种类型实际上在默认导出时可用:

Stack(
 "Somewidget()",Positioned(
   top: "somevalue",child: "DesiredBottomWidget()"),),

我不知道如何在不阅读要使用的每个库的源代码的情况下发现这种事情。