How to add a new type for a function from node_modules?

There is a module react-input-mask.
It is a function of beforeMaskedStateChange, it types not yet described.
Code types from node_modules:
import * as React from 'react';

export interface Selection {
 start: number;
 end: number;
}

export interface InputState {
 value: string;
 selection: Selection | null;
}

export interface MaskOptions {
 mask: string | Array<(string | RegExp)>;
 maskChar: string;
 alwaysShowMask: boolean;
 formatChars: Record<string, string>;
 permanents: number[];
}

export interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
 mask: string | Array<(string | RegExp)>;
 maskChar?: string | null;
 formatChars?: { [key: string]: string };
 alwaysShowMask?: boolean;
 inputRef?: React.Ref<HTMLInputElement>;

beforeMaskedValueChange?(
 newState: InputState,
 oldState: InputState,
 userInput: string,
 maskOptions: MaskOptions,
 ): InputState;
}

export class ReactInputMask extends React.Component<Props> {
}

export default ReactInputMask;

I need to add a type for a function that is similar to beforeMaskedValueChange - beforeMaskedStateChange.
Create in src folder @types, then the folder with the module name and the index file, in it (how it works):
declare module 'react-input-mask' {
 import * as React from 'react';

 export interface Selection {
 start: number;
 end: number;
}

 export interface InputState {
 value: string;
 selection: Selection | null;
}

 export interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
 mask: string | (string | RegExp)[];
 maskChar?: string | null;
 formatChars?: { [key: string]: string };
 alwaysShowMask?: boolean;
 inputRef?: React.Ref<HTMLInputElement>;
beforeMaskedStateChange?({
 nextState: InputState,
 previousState: InputState,
 currentState: InputState,
 }): InputState;
}
 export class ReactInputMask extends React.Component<Props> {}
 export default ReactInputMask;
}

But how to do that in the past, it was possible to exportnet only one function - beforeMaskedStateChange?
To Meril types my and from node_modules.
PS Not to be confused beforeMaskedStateChange c beforeMaskedValueChange.
April 19th 20 at 12:06
0 answer

Find more questions by tags TypeScript