IMaskInput type not working properly "Typescript"
Describe the bug
IMaskInput is not typed properly and result with this typing -> const IMaskInput: React.ComponentType<{}>
IMaskInput is not taking any props like mask,definitions etc. and make it not usable with typescript at all (Atleast the way i'm configured).

Is there something I'm missing ?
To Reproduce I have typescript 4.4.3, React 17.0.2 with Imask 6.2.2
Environment:
- OS: Windows
- Browser Chrome
- IMask 6.2.2
- typescript 4.4.3, React 17.0.2
I am experiencing the same issue
I'm getting the same error and don't know how to handle it yet.
I am also having the same issue, will update if I can come up with a fix other than just using //@ts-ignore on each line.
Pretty certain it's because the return type on IMaskMixin overwrites the incoming types. So it goes through all the effort of bringing in a typed component, just to return a blank React.ComponentType.
https://github.com/uNmAnNeR/imaskjs/blob/2c5dad60d62d21614b895138c6c0369219ab88a4/packages/react-imask/src/mixin.ts#L108-L114
On compile, I think typescript notices this and simplifies the compiled types for anything wrapped with IMaskMixin to the following output
import React from 'react';
declare const IMaskInput: React.ComponentType<{}>;
export default IMaskInput;
Downgrading to 6.1.0 solves while it is not solved.
Having this issue as well. Downgrading did not work for me because types are not available in 6.1.0. We are also not allowed to use ts-ignore, therefore adding //@ts-expect-error with a description solves the issue for now. Looking forward to an update / fix.
Any updates on when this will be fixed?
Any suggestion ?
@mcatal
I add a this temp fix to pass the build:
// @ts-ignore: hot fix for https://github.com/uNmAnNeR/imaskjs/issues/554
import { IMaskInput } from 'react-imask';
error:
Step #0: Type error: Could not find a declaration file for module 'react-imask'. '/app/node_modules/react-imask/dist/react-imask.js' implicitly has an 'any' type.
Step #0: Try `npm i --save-dev @types/react-imask` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-imask';`
Step #0:
To work properly with typescript I found that the path to index.d.ts should be added in types property in package.json file. I guess it could fix issues with typescript.
Now it is missed here: https://github.com/uNmAnNeR/imaskjs/blob/master/packages/react-imask/package.json
Documentation: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
There exist a pull request that can close this issue -> https://github.com/uNmAnNeR/imaskjs/pull/576
While that PR is in the wings, there is a change you can make to typeRoots in your tsconfig.json file to tell Typescript where these type files are within react-imask. https://www.typescriptlang.org/tsconfig#typeRoots
"compilerOptions": {
...,
// If you don't already use this config option, you'll need to explicitly add your node_module/@types folders
"typeRoots": [
"./node_modules/@types",
"../../node_modules/@types", // If you're in a workspace, you may have a hoisted @types.
/**
* react-imask has types but does not specify where they are in its package.json file.
* @see https://github.com/uNmAnNeR/imaskjs/pull/576
*/
"../../node_modules/react-imask/dist/index.d.ts",
],
}
Since none of the provided solutions here worked for me, my quick and dirty workaround is to change the types of the component to any
For using IMaskMixing, (React.ComponentTypeexport default function IMaskMixin<Opts extends IMask.AnyMaskedOptions = IMask.AnyMaskedOptions, Unmask extends ('typed' | boolean) = false, Value = Unmask extends 'typed' ? IMask.InputMask<Opts>['typedValue'] : Unmask extends Falsy ? IMask.InputMask<Opts>['value'] : IMask.InputMask<Opts>['unmaskedValue']>(ComposedComponent: React.ComponentType<IMaskMixinProps<Opts, Unmask, Value>>): React.ComponentType<any>;
For using IMaskInput replace in input.d.ts):
import React from 'react';
declare const IMaskInput: React.ComponentType<any>;
export default IMaskInput;
@uNmAnNeR It appears it's not possible to pass unmask to IMaskMixin without type errors. Is this by design or an accident?
Happy to open another issue as relevant.

@uNmAnNeR It appears it's not possible to pass
unmasktoIMaskMixinwithout type errors. Is this by design or an accident?Happy to open another issue as relevant.
I'm also experiencing this issue
@uNmAnNeR It appears it's not possible to pass
unmasktoIMaskMixinwithout type errors. Is this by design or an accident? Happy to open another issue as relevant.I'm also experiencing this issue
Same here. Any workarounds?
I'm using hook-form and react-imask, and it was solved using these versions:
"react-hook-form": "^7.51.0",
"react-imask": "7.1.3"