jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.1k stars 111 forks source link

Added TypeScript definitions. #46

Closed elongl closed 10 months ago

jamesisaac commented 6 years ago

Yup this would be a good addition, thanks. Although of course want to support both Flow and TypeScript, so shouldn't be deleting the existing types.js file.

Also, does the current project setup actually work with TypeScript, given that the Flow types are baked into the code? I think probably for full TS support I should add a postpublish hook that does a babel transpilation to pure JS?

elongl commented 6 years ago

Ohhh, you're right. Didn't notice the Flow typing. This should remain. And the current setup does not support TypeScript, just adding index.d.ts would do the job. I'll edit my branch and then I'd appreciate it if you merge.

jamesisaac commented 6 years ago

But even with your branch, don't the Flow types in index.ios.js confuse TypeScript?

nickserv commented 6 years ago

I think probably for full TS support I should add a postpublish hook that does a babel transpilation to pure JS?

I believe you need to do this, unless React Native has built in Flow type stripping, even if you just want to use JS and not necessarily TS.

elongl commented 6 years ago

Worth mentioning, the new package worked for me just by adding the index.d.ts file. Just describe the default export of the module.

jamesisaac commented 6 years ago

@nickmccurdy Yes, agreed. It was my mistake of not thinking outside the default stack RN promotes, which generally does have Flow support. I'll get that and a few other changes I've had in mind into the project and bump the version.

I'm just curious how @elongl is having success with TS despite the Flow types. Maybe a build pipeline which has Babel with flow-strip-types, then feeding into TS or something..?

nickserv commented 6 years ago

TypeScript declaration files tell the typechecker to completely ignore the source file.

jamesisaac commented 6 years ago

Isn't TS pretty much always used as a transpiler as well as a typechecker though? Or has this changed with Babel 7?

nickserv commented 6 years ago

Yes, but the compiler will see the Flow syntax, not the typechecker.

jamesisaac commented 6 years ago

So you'd expect this to report no type errors, but give a syntax error when it comes to compiling?

@elongl Could you confirm whether your project actually compiles and runs successfully?

nickserv commented 6 years ago

I'm not sure, it depends on React Native's build process and how a TypeScript user would set up their build process.

elongl commented 6 years ago

@jamesisaac Yes it does. You're more than free to clone this project, add the index.d.ts file to the module in node_modules and see for yourself. It recognizes the typing and simply suggests it for me as I code. Everything compiles and runs well. I genuinely invite you to try it, just to make sure that I'm not missing something. As far as I see it, no problem.

jamesisaac commented 6 years ago

Thanks, will give it a look over when I get a chance.