2017-01-14 5 views
2

uuidv5のTypescript宣言を作成しようとしています。これはサードパーティ製モジュールの最初の宣言で、理解できない構文を使用しています。裸のモジュールは次のようになります。ほとんど私は宇宙の列挙型にアクセスすることができないという事実を除いて、私が欲しいものを得ているuuidv5のTypescript宣言で、enumとdefault関数の両方をエクスポートします

declare module uuidv5 { 
    type uuid = string | Buffer 
    enum space { dns, url, oid, x500, null, default } 
    type ns = uuid | space 

    export interface createUUIDv5 { 
     (namespace: ns, name: uuid): uuid; 
     (namespace: ns, name: uuid, binary: boolean): uuid; 

     uuidToString(uuid: Buffer): string; 
     uuidFromString(uuid: string): Buffer; 
     createUUIDv5: uuidv5.createUUIDv5; 
     space: uuidv5.space; 
    } 
} 

declare const exp: uuidv5.createUUIDv5; 
export = exp; 

function uuidToString(uuid) { 
} 

function uuidFromString(uuid) { 
} 

function createUUIDv5(namespace, name, binary) { 
} 

createUUIDv5.uuidToString = uuidToString; 
createUUIDv5.uuidFromString = uuidFromString; 

module.exports = createUUIDv5; 

私はこのような宣言を作成しようとしました

var uuidNs = uuidv5(uuidv5.spaces.null, "My Space", true); 
        ------------------ 
var uuid = uuidv5(uuidNs, "My Space", true); 

を使用して、私は、ドキュメントを経て、それでも一番上に型定義のためにそれを使用することができることながら、そこにその列挙型を追加する方法を見つけることができません...

+0

あなたはモジュールから 'space'列挙型をエクスポートしようとしていますか? – timocov

+0

私はそうだと思います。私はそれを使用しようとすると、現時点では表示されず、コンパイルもされません。 – jessehouwing

答えて

2
declare module uuidv5 { 
    type uuid = string | Buffer 
    enum space { dns, url, oid, x500, null, default } 
    type ns = uuid | space 

    export interface createUUIDv5 { 
     (namespace: ns, name: uuid): uuid; 
     (namespace: ns, name: uuid, binary: boolean): uuid; 

     uuidToString(uuid: Buffer): string; 
     uuidFromString(uuid: string): Buffer; 
     createUUIDv5: uuidv5.createUUIDv5; 
     spaces: typeof uuidv5.space; // notice this line 
    } 
} 

declare const exp: uuidv5.createUUIDv5; 
export = exp; 

declare module uuidv5形式を使用することは推奨されていません。推奨されていません。 ES6モジュールと互換性のある環境モジュールが優れています。使用の際に

declare module 'uuidv5' { 
    type uuid = string | Buffer 
    enum space { dns, url, oid, x500, null, default } 
    type ns = uuid | space 

    interface createUUIDv5 { 
     (namespace: ns, name: uuid): uuid; 
     (namespace: ns, name: uuid, binary: boolean): uuid; 

     uuidToString(uuid: Buffer): string; 
     uuidFromString(uuid: string): Buffer; 
     createUUIDv5: createUUIDv5; 
     spaces: typeof space; 
    } 
    var exp: createUUIDv5 
    export = exp 
} 

import * as uuidv5 from 'uuidv5' 

var uuidNs = uuidv5(uuidv5.spaces.null, "My Space", true); 
+0

ありがとう!それは完璧に働いた。答えを見ると、それはとても明らかになります:)。 – jessehouwing

関連する問題