question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript support

See original GitHub issue

Hello,

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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
horacehyleecommented, Jul 18, 2018

To whom it may concern, the proper way of importing react-number-format should be

import { default as NumberFormat } from 'react-number-format';

which then can set noImplicitAny to true and without having to use require 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.

0reactions
Mario-Eiscommented, Mar 15, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found