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

polish raven.d.ts #827

Merged
merged 23 commits into from
Mar 20, 2017
Merged

polish raven.d.ts #827

merged 23 commits into from
Mar 20, 2017

Conversation

LucaVazz
Copy link
Contributor

as discussed in #820

  • added missing public functions from raven.js
  • moved complex data types into helper interfaces
  • corrected wrong definitions
  • reordered things a bit

Please double-check that everything has the correct data types, according to the JS-Side.

- added missing public functions from raven.js
- moved complex data types into helper interfaces
- corrected wrong definitions
- reordered things a bit
@benvinegar
Copy link
Contributor

cc @connor4312 – mind chiming in on this?

*
* @param user The definition of the currently active user's unique identity
*/
setUserContext(user: RavenUserContext): RavenStatic;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the overload and just have user?: RavenUserContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But if the overload is removed, the difference in the documentation is lost.

As the function behaves (a bit) differently, if you pass it nothing or a RavenUserContext, I wanted to also reflect that in the inline-/tooltip -documentation

* Specify a callback function that determines if the given message should be sent to Sentry.
* @param callback The function which determines if the given blob should be sent
*/
setShouldSendCallback(callback: (data: any, orig?: string) => boolean): RavenStatic;
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a lot of anys! Can we get some more specific typings on them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It sure is...
I will look into it again if it is (reasonably) possible to be more specific about the data passed to these various callbacks

@connor4312
Copy link
Contributor

Looks mostly fine as far as the typings themselves go, I've not verified that all data types are correct against the Js implementation.

@benvinegar
Copy link
Contributor

benvinegar commented Jan 20, 2017

Okay, CI isn't running npm test (will fix), otherwise we'd see:

> raven-js@3.9.1 test-typescript /Users/benvinegar/Projects/raven-js
> node_modules/typescript/bin/tsc --noEmit --noImplicitAny typescript/raven-tests.ts

typescript/raven-tests.ts(1,21): error TS2307: Cannot find module 'raven-js'.

So, this is the problem I have every time I try to touch our module definition: I cannot come up with a consistent export that works wherever.

Can someone here help me? Am I invoking tsc incorrectly?

@benvinegar
Copy link
Contributor

Also, why rename to RavenJS? I'd kind of prefer if it was just Raven.

@LucaVazz
Copy link
Contributor Author

If I remember it correctly, a tsconfig.json is needed in ./typescript to successfully run tsc; somehow the file got lost...
I will add it later.
As far as I can tell you are invoking tsc correctly nonetheless.

RavenJS is only a local name inside raven-tests.ts, so it should be possible to change it without a problem.

@benvinegar
Copy link
Contributor

@LucaVazz – again, really appreciate your continued effort on this. I've re-enabled the tsc test in CI to help facilitate.

@LucaVazz
Copy link
Contributor Author

I took me a little longer then I expected to get around to doing this...

Now tsc works without errors and I made any wherever I could more specific.

Copy link
Contributor

@benvinegar benvinegar left a comment

Choose a reason for hiding this comment

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

See comments: really just questions.

Raven.setEnvironment('production');

Raven.setDataCallback(function (data: any) {});
Raven.setDataCallback(function (data: any, original: any) {});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove these from tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was not intentional.
As to why it did happen... Good question.

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 in 1f55f01



// --- Helper Interfaces for Options --------------
export interface RavenBreadcrumOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Breadcrum

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 in 3e51fc6

colno: string;
function:string;
in_app: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

At 387 lines, this definition file is almost as complicated as Raven.js itself. Is it normal for libraries to expose something so rigid? I'm terrified this file will become really painful to maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I agree with what @connor4312 previously said: More specific type definitions are always better.
Unfortunately I don't see a way to compress the type definitions for Raven more...

One way to ensure a bit easier maintainability would be to switch the main Raven-JS to TypeScript. It wouldn't be a change that drastically, especially considering that TypeScript transpiles down to vanilla JS in the end.

Copy link
Contributor

Choose a reason for hiding this comment

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

One way to ensure a bit easier maintainability would be to switch the main Raven-JS to TypeScript. It wouldn't be a change that drastically, especially considering that TypeScript transpiles down to vanilla JS in the end.

This will not happen :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay then ;)

But still, I don't think that it would be that hard to maintain this file onwards. In my opinion it is "just" another documentation of the Raven Module, like a more specific version of JSDoc which you already use.
Maybe @connor4312 has some additional opinion...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, so. I would mention that although the length may be comparable to raven.js itself, the complexity is significantly lower; it's static definitions, not procedural code.

That said, it is a maintenance burden, and it's definitely your prerogative whether that's something you want to take up. Someone will have to take it up, if nothing else maintaining definitions in DefinitelyTyped. It could be reduced by making pull request templates and having an issue checkmark for "[x] I updated typings/raven.d.ts if I added to or changed the API". I'd be happy to assist with reviews for those if you'd like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that is a really good idea @connor4312!

I have added a Proposal for a PR-Template which includes that. What do you think of it @benvinegar?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're to add such a template, I'd rather it not be part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, then I will try that in a separate Request.


export interface RavenBreadcrumb {
message: string;
data: { [id: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this allow for free-form objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the RavenUserContext or RavenBreadcrumb?

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
Copy link
Contributor

Choose a reason for hiding this comment

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

What can we do to guarantee that users, no matter what environment, will be able to import this project fine? Do we have to document, "please see our tsconfig settings"?

Would you expect the export/module TypeScript definition change to result in a new major rev (4.x.x)?

Copy link
Contributor Author

@LucaVazz LucaVazz Jan 25, 2017

Choose a reason for hiding this comment

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

No, this tsconfig settings only define the structure and compilerOptions for this module. Users should be able to import the module fine as long as our type definitions are correct, regardless if their project's tsconfig settings match these or not.

In my opinion this is still a non-breaking change, as long as users used the interface correctly. I didn't change anything major at the tests (as I said, the Deletion was unintentional) and they still pass.

@benvinegar
Copy link
Contributor

Okay, so the blocker for me right now has little to do with this PR (sort of).

It's that if you try to do this in a SystemJS project:

import Raven from 'raven-js';

SystemJS will look for .default on the imported Raven instance, and none exists (because we're not building one that way in our Grunt build).

That's why, up until now, we've advocated doing:

var Raven = require('raven-js');

Which does not look for a default property and works. It looks like I can still use this require statement even with the export changes you've done in this definition file. Can anyone confirm?

***Release Type:***
- [ ] Major
- [ ] Minor
- [X] Patch
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this.

***Checklist:***
- [ ] I have included appropriate Tests and have run `npm test` without errors
- [ ] I have updated the Documentation accordingly
- [ ] I updated typings/raven.d.ts if I added to or changed the API and have run `tsc --noEmit --noImplicitAny typescript/raven-tests.ts` without errors
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably make this a script like npm run test:ts, or make it called by npm test directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just noticed that in fact it already is called directly by npm test 😁

@LucaVazz
Copy link
Contributor Author

Regarding SystemJS: On the one hand I don't see a reason why the way you outlined wouldn't work anymore.
On the other hand I'm unfortunately not really experienced with SystemJS so someone else should better verify it....

@LucaVazz
Copy link
Contributor Author

LucaVazz commented Feb 16, 2017

the last two commits integrated changes suggested by @evilj0e in DefinitelyTyped/DefinitelyTyped#14674

Copy link
Contributor

@benvinegar benvinegar left a comment

Choose a reason for hiding this comment

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

Please remove PULL_REQUEST_TEMPLATE (see other comment) and I'll go ahead and merge.

colno: string;
function:string;
in_app: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're to add such a template, I'd rather it not be part of this PR.

@benvinegar
Copy link
Contributor

Haven't forgotten about this. I'll merge it for the next minor release (3.13.0).

@benvinegar benvinegar merged commit 4e12341 into getsentry:master Mar 20, 2017
benvinegar added a commit that referenced this pull request Mar 22, 2017
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.

3 participants