我正在尝试.d.ts
为此灯塔文件创建一个,并且努力了解如何处理默认导出
https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/index.js#L28
module.exports = function(url, flags = {}, configJSON) {
const startTime = Date.now();
return Promise.resolve().then(_ => {
// set logging preferences, assume quiet
flags.logLevel = flags.logLevel || 'error';
log.setLevel(flags.logLevel);
// Use ConfigParser to generate a valid config file
const config = new Config(configJSON, flags.configPath);
const connection = new ChromeProtocol(flags.port, flags.hostname);
// kick off a lighthouse run
return Runner.run(connection, {url, flags, config})
.then(lighthouseResults => {
// Annotate with time to run lighthouse.
const endTime = Date.now();
lighthouseResults.timing = lighthouseResults.timing || {};
lighthouseResults.timing.total = endTime - startTime;
return lighthouseResults;
});
});
};
module.exports.getAuditList = Runner.getAuditList;
module.exports.traceCategories = require('./gather/driver').traceCategories;
module.exports.Audit = require('./audits/audit');
module.exports.Gatherer = require('./gather/gatherers/gatherer');
在这个阶段,我的lighthouse.d.ts
项目中有一个文件:
declare module "lighthouse" {
export interface flags {
port: number;
disableCpuThrottling: boolean;
disableDeviceEmulation: boolean;
disableNetworkThrottling: boolean;
}
export default function lighthouse(url: string, flags: flags, perfConfig: any): any
}
它似乎输入正确。如果我使用 导入import * as lighthouse from "lighthouse";
,我可以在我需要的地方lighthouse.default
做。lighthouse.flags
但是如果我运行我的代码,我会得到TypeError: lighthouse.default is not a function
. 我是否被迫使用export =
?如果我没有选择,如何使用export =
但导出函数、flags
类型和getAuditList
, traceCategories
, Audit
, Gatherer
?