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

Do not emit @type if @define is specified #1003

Merged
merged 7 commits into from
Mar 20, 2019
Merged

Do not emit @type if @define is specified #1003

merged 7 commits into from
Mar 20, 2019

Conversation

shicks
Copy link
Contributor

@shicks shicks commented Mar 14, 2019

Instead, just trust whatever type is specified in @define, which should be either string, number, or boolean.

This is a blocker for rolling out the new module-compatible style of goog.define to TypeScript code.

Instead, just trust whatever type is specified in @define, which should be either string, number, or boolean.
src/jsdoc.ts Outdated Show resolved Hide resolved
src/jsdoc.ts Outdated Show resolved Hide resolved
src/jsdoc_transformer.ts Outdated Show resolved Hide resolved
test_files/jsdoc/jsdoc.ts Outdated Show resolved Hide resolved
@shicks
Copy link
Contributor Author

shicks commented Mar 16, 2019

Addressed the points. PTAL.

src/jsdoc_transformer.ts Outdated Show resolved Hide resolved
src/jsdoc_transformer.ts Outdated Show resolved Hide resolved
src/jsdoc.ts Outdated Show resolved Hide resolved
@shicks
Copy link
Contributor Author

shicks commented Mar 19, 2019

This should be ready to merge, though it will need some cleanup internally to go along with any CL that brings it in, since all the types on @defines are now warnings.

/**
* @define
*/
const DEFINE_WITH_DECLARED_TYPE: string = 'y';
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, this looks good!

src/jsdoc.ts Outdated Show resolved Hide resolved
@shicks
Copy link
Contributor Author

shicks commented Mar 20, 2019

No, if you look at the jsdoc.js test case, you'll see the badConstThing property declared as @type {string} instead of @const {string}. It doesn't matter if warnings are promoted to errors, but if folks are running this without promoting warnings to errors then this could be unfortunate.

With only a single required annotation and no optional, I'm less sold on the win with the map, though in my opinion it is more readable: (a) using an enum rather than an inline condition makes it clear why it's doing what it's doing, and (b) it's potentially less repetition of the condition, depending on how it's structured. But I tried removing it and the diff looks a little cleaner, so I'm fine with that.

In terms of adding more in the future, we have a few internal annotations around mods that take arguments and might want to go here. Though I can also see an argument for adding those in a separate Set JSDOC_TAGS_WITH_NON_TYPE_ARGS (or just ..._WITH_ARGS).

@mprobst
Copy link
Contributor

mprobst commented Mar 20, 2019

No, if you look at the jsdoc.js test case, you'll see the badConstThing property declared as @type {string} instead of @const {string}. It doesn't matter if warnings are promoted to errors, but if folks are running this without promoting warnings to errors then this could be unfortunate.

Yes, tsickle behaves like TS in here (and like JSCompiler) in that it produces output even for incorrect user code. The question is how much effort we should put into emitting something that'll still likely work. With tsickle in general and @define in particular, I'd wager that essentially all users are in bazel or google3, and thus always have these warnings emit errors. So effectively, users should be safe.

There's a question whether we should have ever had this warnings mechanism, I'm not convinced it's useful for anyone. Then again we apparently have some users who use tsickle as a preprocessor to produce JSDoc, they don't care about the effects on JSCompiler at all. Can't really pick your use cases ...

I'll take this over and land it.

@mprobst mprobst merged commit c0ac57b into angular:master Mar 20, 2019
@shicks
Copy link
Contributor Author

shicks commented Mar 20, 2019

Thanks!

mprobst pushed a commit that referenced this pull request Mar 22, 2019
Instead, disallow types in `@define` and fill in the TypeScript type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants