react-native-background-task icon indicating copy to clipboard operation
react-native-background-task copied to clipboard

Added TypeScript definitions.

Open elongl opened this issue 7 years ago • 13 comments

elongl avatar Jun 24 '18 18:06 elongl

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?

jamesisaac avatar Jun 25 '18 21:06 jamesisaac

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.

elongl avatar Jun 25 '18 21:06 elongl

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

jamesisaac avatar Jun 25 '18 21:06 jamesisaac

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.

nickserv avatar Jun 25 '18 21:06 nickserv

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

elongl avatar Jun 25 '18 21:06 elongl

@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..?

jamesisaac avatar Jun 25 '18 21:06 jamesisaac

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

nickserv avatar Jun 25 '18 21:06 nickserv

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

jamesisaac avatar Jun 25 '18 22:06 jamesisaac

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

nickserv avatar Jun 25 '18 22:06 nickserv

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?

jamesisaac avatar Jun 25 '18 22:06 jamesisaac

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

nickserv avatar Jun 25 '18 22:06 nickserv

@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.

elongl avatar Jun 25 '18 22:06 elongl

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

jamesisaac avatar Jun 25 '18 23:06 jamesisaac