2017-05-01 1 views
0

Also machte ich meine eigene Art def für ein Modul:Typoskript Export beide Klasse und Typen

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; 
} 

So, jetzt, was ich tun kann, dass überall:

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

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

und es funktioniert! Aber ich möchte jetzt in der Lage sein, zu tun

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

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

Wenn ich versuche, export hinzufügen vor jedem type in meinem Modul Erklärung sagt, dass es am Ende auf export = ..., dass es nicht mit anderen Exporte exportieren. Wie kann ich auf meine Dateien aus einer anderen Datei zugreifen?

Antwort

0

Nach @types/bluebird mit einem genaueren Blick überprüft, fand ich, dass:

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; 
} 

war das, was ich suchte

+0

Ja, das ist der Weg zu gehen. Viele DT-Typen sollten auf dieses Format umgestellt werden. :) – unional

+0

BTW, warum sie nicht das Modul declare modue verwenden? – Vinz243

+0

https://github.com/types/* ist nicht 'npm install @ types/*'. 'npm install @ types/*' kommt von https://github.com/definitelyped/definitelytyped – unional

Verwandte Themen