Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
364 stars 61 forks source link

Typescript buttonRef.current?.removeFile(e) possibly undefined #91

Open jacobdubail opened 3 years ago

jacobdubail commented 3 years ago

Hi,

I'm running react-papaparse 3.16.1 and @types/papaparse 5.2.6

When I add

if (buttonRef?.current) {
      buttonRef.current?.removeFile(e)
}

in a callback, I get the following Typescript error:

Object is possibly 'undefined'. ts(2532)
(property) MutableRefObject<undefined>.current: undefined

I am basing my component on this: https://github.com/Bunlong/react-papaparse/blob/1709ffb76e9fcd356592474126d57effc4388cb8/demo/CSVReader1.js#L35

Any idea how I can resolve this one?

Thank you!