我想創建我的第一個Typescript定義文件。主題代碼是filename.js(index.js):Typescript「導出的外部封裝類型不是一個模塊」
module.exports = {
extension: extension,
basename: basename,
removeSuffix: removeSuffix,
removeSuffixWithDelimiter: removeSuffixWithDelimiter,
appendSuffix: appendSuffix,
appendSuffixWithDelimiter: appendSuffixWithDelimiter,
directoryName: directoryName
}
function extension(filename) {}
function basename(filename) {}
function removeSuffix(filename) {}
function removeSuffixWithDelimiter(delimiter, filename) {}
function appendSuffix(suffix, filename) {}
function appendSuffixWithDelimiter(suffix, delimiter, filename) {}
function directoryName(filename) {}
定義(index.d.ts)文件我到目前爲止有:
declare module "filename.js" {
export function extension(filename: string): string;
export function basename(filename: string): string;
export function removeSuffix(filename: string): string;
export function removeSuffixWithDelimiter(delimiter: string|number, filename: string): string;
export function appendSuffix(suffix: string, filename: string): string;
export function appendSuffixWithDelimiter(suffix: string, delimiter: string|number, filename: string): string;
export function directoryName(filename: string): string;
}
此作品不夠好(自動完成的作品在我的編輯),但我得到一個編譯錯誤:
index.ts(21,29): error TS2656: Exported external package typings file 'filename.js/index.d.ts' is not a module. Please contact the package author to update the package definition.
這個錯誤是什麼意思(新打字稿),更重要的是,我應該怎麼修改我的定義,使之更正確?
你能解決這個問題嗎?我有同樣的問題。 – emzero
@emzero no我目前還沒有能力 –
希望它會在TS 2.0中修復 – emzero