bvaughn / react-highlight-words

React component to highlight words within a larger body of text
https://bvaughn.github.io/react-highlight-words/
MIT License
2.16k stars 170 forks source link

Missing typescript typings #60

Closed tvthatsme closed 5 years ago

tvthatsme commented 6 years ago

I'd like to work on this, but it would be helpful if the project included the type definitions for anyone who wants to include this in a project using typescript.

Unless you object, I will raise a PR within a day or two, ... or sooner 😃

bvaughn commented 6 years ago

For definitely typed? Sure sounds fine.

On Sun, Jul 22, 2018, 9:16 PM Timothy Vernon notifications@github.com wrote:

I'd like to work on this, but it would be helpful if the project included the type definitions for anyone who wants to include this in a project using typescript.

Unless you object, I will raise a PR within a day or two, ... or sooner 😃

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bvaughn/react-highlight-words/issues/60, or mute the thread https://github.com/notifications/unsubscribe-auth/AABznR1z8QNP0eAJytyzmv51mFo4g-7Kks5uJU4pgaJpZM4VaVpq .

jsphweid commented 6 years ago

Wait, doesn't this exist here already: https://www.npmjs.com/package/@types/react-highlight-words?

But honestly, I get errors when importing in a typescript project.

import * as Highlighter from 'react-highlight-words' // works but with warnings
import Highlighter from 'react-highlight-words' // blows up
import Highlighter from 'react-highlight-words' // doesn't work
const Highlighter = require('react-highlight-words') // works

This is how it's exported in the d.ts but it probably isn't quite right? My guess is that this snippet below is the reason why you get warnings when you try the first line in the above code.

declare class Highlighter extends React.Component<HighlighterProps> {}
export default Highlighter;
damiangreen commented 5 years ago

Anyone working on a fix ? I get a compilation error for import * as .. JSX element type 'Highlighter' does not have any construct or call signatures. second one doesnt work for me

bvaughn commented 5 years ago

TypeScript types for this lib should go to the DefinitelyTyped repo, rather than here. The "fix"would be to open a PR there. 😊