Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create typing definition file or as a separate @types module, for TypeScript #4

Open
yuriys-kentico opened this issue Apr 3, 2019 · 0 comments

Comments

@yuriys-kentico
Copy link

I have used this library with React and TypeScript and created this typing definition to not have my compiler complain:

import { Component, ComponentLifecycle } from "react";

export declare function enableUniqueIds(component: Component): void;
export declare function resetUniqueIds(): void;

declare module "react" {
    export interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {
        nextUniqueId(): string;
        lastUniqueId(): string;
        getUniqueId(identifier: string): string;
    }
} 

It is possible another interface would be a better spot for this, however I have used this with React.PureComponent and observed the expected results (i.e. an element had id="id-2-1").

I used it by manually adding the typing definition file to node_modules. Here is a class with this in use TransformedImagesElement/src/components/editor/inputs/SwitchInput.tsx. Manually adding it is not ideal, which leads to two possible solutions:

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

No branches or pull requests

1 participant