From f486782118baf4c29ba2b4c31ecd7f69623291be Mon Sep 17 00:00:00 2001 From: Hinaser Date: Fri, 25 Jan 2019 18:48:31 +0900 Subject: [PATCH 1/2] [uuidv4] Add types --- types/uuidv4/index.d.ts | 34 ++++++++++++++++++++++++++++++++++ types/uuidv4/tsconfig.json | 23 +++++++++++++++++++++++ types/uuidv4/tslint.json | 1 + types/uuidv4/uuidv4-tests.ts | 13 +++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 types/uuidv4/index.d.ts create mode 100644 types/uuidv4/tsconfig.json create mode 100644 types/uuidv4/tslint.json create mode 100644 types/uuidv4/uuidv4-tests.ts diff --git a/types/uuidv4/index.d.ts b/types/uuidv4/index.d.ts new file mode 100644 index 0000000000..e181a39244 --- /dev/null +++ b/types/uuidv4/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for uuidv4 2.0 +// Project: https://github.com/thenativeweb/uuidv4#readme +// Definitions by: Rindo Hinase +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare const uuidv4: UUIDv4; + +interface UUIDv4_is { + (value: string): boolean; +} + +type EmptyUUIDv4 = '00000000-0000-0000-0000-000000000000'; + +interface UUIDv4_empty { + (): string; +} + +interface UUIDv4_FromString { + (text: string): string; +} + +interface UUIDv4 { + (): string; + is: UUIDv4_is; + empty: UUIDv4_empty; + fromString: UUIDv4_FromString; +} + +// If you read this because linter warns you like '... has no default export' +// please try to write import statement like +// import * as uuidv4 from 'uuidv4' +// rather than +// import uuidv4 from 'uuidv4' +export = uuidv4; diff --git a/types/uuidv4/tsconfig.json b/types/uuidv4/tsconfig.json new file mode 100644 index 0000000000..4ae973d9cb --- /dev/null +++ b/types/uuidv4/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "strictFunctionTypes": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "uuidv4-tests.ts" + ] +} diff --git a/types/uuidv4/tslint.json b/types/uuidv4/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/uuidv4/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/uuidv4/uuidv4-tests.ts b/types/uuidv4/uuidv4-tests.ts new file mode 100644 index 0000000000..0c5f915d95 --- /dev/null +++ b/types/uuidv4/uuidv4-tests.ts @@ -0,0 +1,13 @@ +import * as uuidv4 from 'uuidv4'; // uuidv4 is () => string + +// $ExpectType string +uuidv4(); + +// $ExpectType string +uuidv4.empty(); + +// $ExpectType boolean +uuidv4.is('00000000-0000-0000-0000-000000000000'); + +// $ExpectType string +uuidv4.fromString("test"); From 0bb06233bd7a9595be5e4c249955a2b98ce599bc Mon Sep 17 00:00:00 2001 From: Hinaser Date: Sat, 26 Jan 2019 16:35:44 +0900 Subject: [PATCH 2/2] Restructured to more appropriate type definition --- types/uuidv4/index.d.ts | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/types/uuidv4/index.d.ts b/types/uuidv4/index.d.ts index e181a39244..44f8fc4efe 100644 --- a/types/uuidv4/index.d.ts +++ b/types/uuidv4/index.d.ts @@ -3,32 +3,16 @@ // Definitions by: Rindo Hinase // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare const uuidv4: UUIDv4; - -interface UUIDv4_is { - (value: string): boolean; -} - -type EmptyUUIDv4 = '00000000-0000-0000-0000-000000000000'; - -interface UUIDv4_empty { - (): string; -} - -interface UUIDv4_FromString { - (text: string): string; -} - -interface UUIDv4 { - (): string; - is: UUIDv4_is; - empty: UUIDv4_empty; - fromString: UUIDv4_FromString; -} - -// If you read this because linter warns you like '... has no default export' -// please try to write import statement like -// import * as uuidv4 from 'uuidv4' -// rather than -// import uuidv4 from 'uuidv4' export = uuidv4; + +declare function uuidv4(): string; + +declare namespace uuidv4 { + type EmptyUUIDv4 = '00000000-0000-0000-0000-000000000000'; + + function is(value: string): boolean; + + function empty(): string; + + function fromString(text: string): string; +}