mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Bugfix: Change the Export Method of UIDGenerator Class from Named-Export to Default-Export - @types/uid-generator (#39672)
* bugfix: class should be exported default
* bugfix: test failure
* temp
* also export interfaces
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* syntax error fix
* index.d.ts done
* Bugfix: Change the Export Method of UIDGenerator Class from Named-Export to Default-Export
Motivation
In the original package (uid-generator), the class is exported by Default-Export:
module.exports = UIDGenerator;
But in the current version of the type definition, the class is exported by Named-Export:
export const UIDGenerator: UIDGeneratorConstructor;
Which leads to a piece of wrong JavaScript code after compilation:
const uid_generator_1 = require("uid-generator");
const uidgen = new uid_generator_1.UIDGenerator(bitLength);
The correct piece should be:
const uid_generator_1 = require("uid-generator");
const uidgen = new uid_generator_1(bitLength);
So I feel it may be necessary to fix this.
Fixed List
1. Interface Renaming
UIDGenerator -> UIDGeneratorInstance
UIDGeneratorConstructor -> UIDGeneratorClass
In the current version, the name UIDGenerator used as both the name of the interface and the class, which may leads to confusion.
So I give them a little bit more clear names.
2. Default-Export UIDGenerator
3. UIDGeneratorInstance.generate(call-back): Error Parameter Added
In the orginal (uid-generator) package, the call-back function also accepts an error parameter. And when error did triggered, uid parameter may be optional.
4. Corresponding updates in test script
* syntax fix
* add target es2015
* Update types/uid-generator/tsconfig.json
Remove useless spaces.
Co-Authored-By: Emrio <emrio@emrio.fr>
* ES2015 to es6
* Restore to last time test-passed
"target": "ES2015",
* Remove extra spaces
"target": "es6"
* Update types/uid-generator/index.d.ts
Remove the ? from uid parameter.
Co-Authored-By: Emrio <emrio@emrio.fr>
* Update types/uid-generator/uid-generator-tests.ts
uid must be string now.
Co-Authored-By: Emrio <emrio@emrio.fr>
* uid required now
* Remove target option
* add target:es6
This commit is contained in:
parent
1e2b2c39a1
commit
33e4ecd2fc
15
types/uid-generator/index.d.ts
vendored
15
types/uid-generator/index.d.ts
vendored
@ -1,21 +1,22 @@
|
||||
// Type definitions for uid-generator 2.0
|
||||
// Project: https://github.com/nwoltman/node-uid-generator
|
||||
// Definitions by: TheEmrio <https://github.com/TheEmrio>
|
||||
// KyleChine <https://github.com/kylechine>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface UIDGenerator {
|
||||
interface UIDGeneratorInstance {
|
||||
readonly bitSize: number;
|
||||
readonly uidLength: number;
|
||||
readonly baseEncoding: string;
|
||||
readonly base: number;
|
||||
generateSync(): string;
|
||||
generate(): Promise<string>;
|
||||
generate(cb: (uid: string) => any): void;
|
||||
generate(cb: (error: Error|null, uid: string) => any): void;
|
||||
}
|
||||
|
||||
export interface UIDGeneratorConstructor {
|
||||
new (bitSize?: number, baseEncoding?: string): UIDGenerator;
|
||||
new (baseEncoding?: string): UIDGenerator;
|
||||
interface UIDGeneratorClass {
|
||||
new (bitSize?: number, baseEncoding?: string): UIDGeneratorInstance;
|
||||
new (baseEncoding?: string): UIDGeneratorInstance;
|
||||
readonly BASE16: '0123456789abcdef';
|
||||
readonly BASE36: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
readonly BASE58: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
@ -25,4 +26,6 @@ export interface UIDGeneratorConstructor {
|
||||
readonly BASE94: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
}
|
||||
|
||||
export const UIDGenerator: UIDGeneratorConstructor;
|
||||
declare const UIDGenerator: UIDGeneratorClass;
|
||||
|
||||
export { UIDGenerator as default, UIDGeneratorClass, UIDGeneratorInstance };
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import { UIDGenerator } from 'uid-generator';
|
||||
import { default as UIDGenerator } from 'uid-generator';
|
||||
|
||||
new UIDGenerator('abc'); // $ExpectType UIDGenerator
|
||||
const generator = new UIDGenerator(128, 'abc'); // $ExpectType UIDGenerator
|
||||
new UIDGenerator('abc'); // $ExpectType UIDGeneratorInstance
|
||||
const generator = new UIDGenerator(128, 'abc'); // $ExpectType UIDGeneratorInstance
|
||||
|
||||
generator.generateSync(); // $ExpectType string
|
||||
generator.generate(uid => {
|
||||
generator.generate((err, uid) => {
|
||||
err; // $ExpectType Error | null
|
||||
uid; // $ExpectType string
|
||||
});
|
||||
generator.generate().then(uid => {
|
||||
uid; // $ExpectType string
|
||||
}).catch(e => {
|
||||
e; // $ExpectType any
|
||||
});
|
||||
|
||||
generator.bitSize; // $ExpectType number
|
||||
|
||||
Loading…
Reference in New Issue
Block a user