Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript compiler validation of lib/index.d.ts #784

Merged
merged 3 commits into from
Jan 30, 2018

Conversation

d4l-w4r
Copy link
Contributor

@d4l-w4r d4l-w4r commented Jan 26, 2018

I've noticed that there were some lingering errors in the typescript declaration file and that it's really easy to make these small syntax errors when editing the file.
When you then try to use this project in a TypeScript application you will have a lot of trouble because your TypeScript compiler (tsc) will always throw them as errors.

This PR introduces typescript as a devDependency and adds a tsconfig.json to configure the compiler to be fairly strict and only look at lib/index.d.ts without scanning for other files.

Further, a new npm task is added to package.json called validate-ts-declarations which just starts tsc with the options specified in tsconfig.json.

The validate-ts-declarations command is also added as a prerequisite for build-lib. This means that generating the dist/ folder will fail if lib/index.d.ts is broken.

Note: This does not mean that the build will fail because the type declarations don't accurately reflect the actual code. It just checks that the present declarations are valid TypeScript.

Also the compiler will not produce any output files. It will either silently complete or throw compiler errors of the form:

tsc --project ./

lib/index.d.ts(10,53): error TS2304: Cannot find name 'AuthCredential'.
lib/index.d.ts(597,32): error TS8020: JSDoc types can only be used inside documentation comments.
lib/index.d.ts(1035,27): error TS7006: Parameter 'url' implicitly has an 'any' type.

I think it would really help to have this in the project in order to make it easier and safer to contribute missing TypeScript declarations.

@Salakar
Copy link
Member

Salakar commented Jan 26, 2018

Thanks for the nice and precise PR here,

We've discussed this a little and I believe we're all in favour of having this validate as part of the build, maybe even part of the pre-commit hook.

Between us we've not really used TS, but we can see there's quite a few people relying on this so we have been pushing to update it in the past few weeks, so this will help.

cc @chrisbianca @Ehesp both happy with this? TS validating as part of the build step

@d4l-w4r
Copy link
Contributor Author

d4l-w4r commented Jan 26, 2018

Nice! Glad to help out :)

@chrisbianca
Copy link
Contributor

@danielw93 another thanks, this is great! As Mike says, we've been wanting to put some focus on TS for a while and this will definitely help.

I'm happy for this to be merged and we can look to incorporate in the pre-commit hook once we've checked it's working without issue as part of the build process.

@@ -5,6 +5,13 @@

declare module "react-native-firebase" {

/** 3rd party provider Credentials */
type AuthCredential = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielw93 All types here should better be interfaces

@chrisbianca chrisbianca merged commit dd0dd7f into invertase:master Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants