Typescript support
See original GitHub issueHello,
It is currently impossible to import NumberFormat in the ES6 standard manner when using Typescript:
// Doesn't work
import NumberFormat from "react-number-format"
// Workaround
import NumberFormat = require("react-number-format")
It would also be great to include a typing declaration file for automatic auto-completion in IDEs. The following snippet should be a good basis:
declare module 'react-number-format' {
export class NumberFormat extends React.Component<NumberFormatProps, any> {
// Any public method on the NumberFormat component?
}
export interface NumberFormatProps extends React.HTMLAttributes<HTMLInputElement> {
thousandSeparator?: boolean | ',' | '.' | ' '
decimalSeparator?: boolean | ',' | '.'
displayType?: 'input' | 'text'
prefix?: string
format?: string | Function
mask?: string
// value?: number | string
}
export default NumberFormat;
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes ...
Read more >TypeScript - Wikipedia
TypeScript supports definition files that can contain type information of existing JavaScript libraries, much like C++ header files can describe the ...
Read more >TypeScript Programming with Visual Studio Code
Visual Studio Code includes TypeScript language support but does not include the TypeScript compiler, tsc . You will need to install the TypeScript...
Read more >TypeScript | IntelliJ IDEA Documentation - JetBrains
IntelliJ IDEA supports developing, running, and debugging TypeScript source code. IntelliJ IDEA recognizes .ts and .tsx files and provides ...
Read more >TypeScript Introduction - W3Schools
TypeScript is JavaScript with added syntax for types. ... as Visual Studio Code, have built-in TypeScript support and can show errors as you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To whom it may concern, the proper way of importing
react-number-format
should bewhich then can set
noImplicitAny
totrue
and without having to userequire
to import the module.Moreover, my pull request has been merged, so declaration file will be available by default for using Typescript after
v3.4.4
.import * as NumberFormat from 'react-number-format';
only works if “implicit any” is allowed for the project. I would not suggest such a configuration for professional projects. Unfortunately that issue makes react-number-format almost “unusable” for professional scale TypeScript projects.Also the suggest workaround
import NumberFormat = require("react-number-format")
won’t work if the project targets ES modules.