cleave.js icon indicating copy to clipboard operation
cleave.js copied to clipboard

Type definition for `InitHandler` is incorrect causing typescript issues with `onInit` function

Open tommiewatts opened this issue 5 years ago • 2 comments

In @types/cleave.js/react/props.d.ts InitHandler is defined with type React.ReactInstance

import * as React from "react";
import { CleaveOptions } from "../options";

export type InitHandler = (owner: React.ReactInstance) => void;

export interface ChangeEvent<T> extends React.ChangeEvent<T> {
    target: { rawValue: string } & EventTarget & T;
}

export type ChangeEventHandler<T = Element> = React.EventHandler<ChangeEvent<T>>;

export interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
    onInit?: InitHandler;
    options: CleaveOptions;
    htmlRef?: (i: any) => void;
    onChange?: ChangeEventHandler<HTMLInputElement>;
}

This is causing a typescript error when trying to access the owner object functions. Can we update the type here so it matches what is expected?

Screen Shot 2020-07-02 at 10 03 59 AM

tommiewatts avatar Jul 02 '20 17:07 tommiewatts

Hi all -- I wanted to see if this is in the works or if perhaps it is not a priority. Thanks in advance!

juanfabrega avatar Mar 05 '21 14:03 juanfabrega

@tommiewatts @juanfabrega

There is now a PR up in DefinitelyTyped to fix this issue! Not merged yet, but once it is, your problem will be solved.

vivshaw avatar Oct 22 '21 15:10 vivshaw