我正在尝试从包类型中扩展命名空间@typings/fullcalendar.
/// <reference path="./types/fullcalendar" />
import * as fullcalendar from 'fullcalendar';
import { TimeGrid } from 'fullcalendar';
// TimeGrid and fullcalendar.views are used then
Run Code Online (Sandbox Code Playgroud)
原件类型可以在这里看到.
而fullcalendar-custom.d.ts是
import * as FC from 'fullcalendar';
export as namespace FC;
declare class TimeGrid { prepareHits() }
declare let views: any;
Run Code Online (Sandbox Code Playgroud)
这会导致类型错误,因此显然fullcalendar没有正确扩展名称空间:
TS2305:模块'".../node_modules/@ types/fullcalendar/index"'没有导出成员'TimeGrid'.
TS2339:类型'typeof".../node_modules/@ types/fullcalendar/index"'上不存在属性'views'.
该如何以正确的方式完成?
可以reference指令来避免在这里,考虑到types目录中指定typeRoots?
该应用程序与Webpack和awesome-typescript-loader捆绑在一起,因此行为可能与其他编译方法不同.在某些时候,IDE检查(WebStorm)中的类型似乎没问题,但在编译时仍然出现类型错误.