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

Add TypeScript type definitions (from DefinitelyTyped) #610

Merged
merged 6 commits into from
Jun 19, 2016

Conversation

benvinegar
Copy link
Contributor

Greatly facilitates importing Raven.js into a TypeScript project (otherwise you must use an external definition file). Most other major crash reporting platforms embed a definition file in their JS client repository.

This definition file was taken from the DefinitelyType repository, with just a single change: I made Raven the default export for the module, so that this is the same:

import Raven from 'raven-js';

One thing that isn't clear to me, but we can resolve in a later patch, is whether we need the duplicated API documentation / JSDoc strings. I guess one nice thing is that these comments appear in Visual Studio and other tools.

cc @mattrobenolt @santialbo @spartan563

@mattrobenolt
Copy link
Contributor

Can we wire this up with tests so that this doesn't ever diverge from the actual API? I can see someone modifying one without the typescript definition very easily.

@benvinegar
Copy link
Contributor Author

benvinegar commented Jun 17, 2016

So, you should note that this is already a problem today: if we change the Raven.js API, and users download the latest raven-js but nobody updates the DefinitelyTyped repository, they will get type errors during TypeScript compilation.

But ... there is already a test file we can also borrow and run as part of CI. It will at least catch basic stuff and remind us that the definition file fundamentally may need updating. That work?

@mattrobenolt
Copy link
Contributor

If we change the Raven.js API, and users download the latest raven-js but nobody updates the DefinitelyTyped repository, they will get type errors during TypeScript compilation.

Yeah, totally. The difference though is that this definition wasn't even maintained by us. So if we're now choosing to take on the burden of maintaining it correctly, we need to make sure we don't break it.

there is already a test file we can also borrow and run as part of CI. It will at least catch basic stuff and remind us that the definition file fundamentally may need updating. That work?

Seems reasonable, but I have significantly less context about what any of this is. :) I just want to make sure tests catch when we change the API and it breaks the ts definitions.

@benvinegar
Copy link
Contributor Author

benvinegar commented Jun 17, 2016

Seems reasonable, but I have significantly less context about what any of this is. :) I just want to make sure tests catch when we change the API and it breaks the ts definitions.

If I add a new API method, it's going to require that I add a new rule, and an existing test won't catch this. The only possibility of automating this is by doing our own static analysis of public Raven methods (e.g. using Esprima) and verifying that a TypeScript definition exists for each. That is just way, way too much work for what we're getting out of this (right now).

But, a test like the one I linked will at least catch definition file regressions. I think that is an acceptable place to start.

@benvinegar
Copy link
Contributor Author

@mattrobenolt – as always, thank you for pushing me to do this. Adding this test highlighted some issues and I think we're in a good place now.

id: '123'
});
__1["default"].captureMessage('Broken!');
__1["default"].captureMessage('Broken!', { tags: { key: "value" } });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh

ignoreErrors?: string[];

/** Similar to ignoreErrors, but will ignore errors from whole urls patching a regex pattern. */
ignoreUrls?: RegExp[];
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that these don't allow passing strings as well as regexp.


/** Similar to ignoreErrors, but will ignore errors from whole urls patching a regex pattern. */
ignoreUrls?: RegExp[];
ignoreUrls?: RegExp[] | string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

This still doesn't cover the case of:

ignoreUrls: [
  /foo/,
  'bar',
]

Does it?

Copy link
Contributor Author

@benvinegar benvinegar Jun 18, 2016

Choose a reason for hiding this comment

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

Ugh you're right, just tested it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. We're learning TypeScript!

Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

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.

2 participants