2017-05-01 6 views
0

の両方をエクスポートだから私は、モジュールのための私自身のタイプのDEFを作っ:活字体はクラスとタイプ

declare module 'fs-tree-diff' { 
    interface FSEntry { 
    relativePath: string; 
    mode: number; 
    size: number; 
    mtime: number; 
    isDirectory:() => boolean; 
    } 

    type Operation = 'unlink' | 'create' | 'mkdir' | 'change' | 'rmdir'; 
    type PatchEntry = [Operation, string, FSEntry]; 
    type Patch = PatchEntry[]; 

    type FSEntries = FSEntry[]; 

    class FSTree { 
    constructor (options: {entries: FSEntries, sortAndExpand?: boolean}); 
    static fromEntries (entries: FSEntries): FSTree; 
    static fromPaths (paths: string[]): FSTree; 
    addEntries (entries: FSEntries, options: {sortAndExpand: boolean}): void; 
    addPath (paths: string[], options: {sortAndExpand: boolean}): void; 
    forEach (fn: any, context: any): void; 
    calculatePatch (other: FSTree, isEqual?: (a: FSEntry, b: FSEntry) => boolean): Patch; 
    } 

    export = FSTree; 
} 

だから今、私はどこでも行うことができます。

import FSTree = require('fs-tree-diff'); 

const tree = new FSTree({entries: []}); 

、それが作品を!私は私のモジュール宣言、それが他の輸出にエクスポートすることはできませんexport = ...の端部に言うには、すべてのtypeexportを追加しようとした場合しかし、私は

import FSTree = require('fs-tree-diff'); 

const tree = new FSTree({entries: []}); 
let entry: FSTree.FSEntry; 
... 

を行うことができるようになりましたたいと思います。他のファイルから私のdefにアクセスするにはどうすればいいですか?私はその見つかっよく見る、と@types/bluebirdをチェックした後

答えて

0

declare module 'fs-tree-diff' { 
    namespace FSTree { 
    interface FSEntry { 
     relativePath: string; 
     mode: number; 
     size: number; 
     mtime: number; 
     isDirectory:() => boolean; 
    } 

    type Operation = 'unlink' | 'create' | 'mkdir' | 'change' | 'rmdir'; 
    type PatchEntry = [Operation, string, FSEntry]; 
    type Patch = PatchEntry[]; 

    type FSEntries = FSEntry[]; 
    } 

    class FSTree { 
    constructor (options: {entries: FSTree.FSEntries, sortAndExpand?: boolean}); 
    static fromEntries (entries: FSTree.FSEntries): FSTree; 
    static fromPaths (paths: string[]): FSTree; 
    addEntries (entries: FSTree.FSEntries, options: {sortAndExpand: boolean}): void; 
    addPath (paths: string[], options: {sortAndExpand: boolean}): void; 
    forEach (fn: any, context: any): void; 
    calculatePatch (other: FSTree, isEqual?: (a: FSTree.FSEntry, b: FSTree.FSEntry) => boolean): FSTree.Patch; 
    } 

    export = FSTree; 
} 

は、私ははい、それが進むべき道だ

+0

探していたものでした。多くのDT入力はこの形式に変更する必要があります。 :) – unional

+0

btw、彼らはなぜmodue部分を宣言しないのですか? – Vinz243

+0

https://github.com/types/*は 'npm install @ types/*'ではありません。 'npm install @ types/*'はhttps://github.com/definitelytyped/definitelytyped – unional