Skip to content

Add type declarations#2

Open
vitonsky wants to merge 1 commit intojonschlinkert:mainfrom
vitonsky:add-type-declarations
Open

Add type declarations#2
vitonsky wants to merge 1 commit intojonschlinkert:mainfrom
vitonsky:add-type-declarations

Conversation

@vitonsky
Copy link
Copy Markdown

Hey Jon. This PR adds a type declarations in build, to make this code works in typescript code.

Additionally typescript compiler found a mismatch segment implementation to a base class type, since it must return object with method containing and iterator symbol. I've fixed that problem with stub implementation of containing that throws error if will be used. We may create issue to implement this method later.

Now code compiles well. Example of generated .d.ts file is

declare class Segmenter extends Intl.Segmenter {
    private readonly language;
    private readonly options;
    constructor(language: string, options?: Intl.SegmenterOptions & {
        maxChunkLength?: number;
    });
    segment(input: string): Intl.Segments;
    findSafeBreakPoint(input: string): number;
    getSegments(input: string): Intl.SegmentData[];
    static getSegments(input: string, language: string, options?: Intl.SegmenterOptions): Intl.SegmentData[];
}

export { Segmenter };

Please update package once this changes will be merged. I faced with a performance problem that solves your package, so I would be happy to migrate on your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant