Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

TypeScript / tsc drops comments, removes Closure-style casts #411

Closed
mprobst opened this issue Feb 28, 2017 · 5 comments
Closed

TypeScript / tsc drops comments, removes Closure-style casts #411

mprobst opened this issue Feb 28, 2017 · 5 comments

Comments

@mprobst
Copy link
Contributor

mprobst commented Feb 28, 2017

tsickle emits Closure style casts, i.e. JSDoc comments like this:

x = /** @type {foo} */ (y);

tsc drops these, and emits:

x = (y);

This happens in many syntactical positions.

@mprobst mprobst added this to the Warning free typed mode in g3 milestone Feb 28, 2017
@mprobst
Copy link
Contributor Author

mprobst commented Feb 28, 2017

From @evmar

Idea: introduce the Closure version of
function coerce(x: any): T { return X; }
and then use that?

Might be pretty gross depending on how many casts we insert.

Idea #2, pattern t5:

var a;

/** t1 */ x;

/** t2 */ var x;

x = /** t3 */ a;

x = /** t4 */ (a);

x = ((/** t5 */ a) => a)(a);

Idea #3 is of course fixing it upstream but I dunno how hard that is. I tried before and it seemed fairly hard but I didn't understand the code very well.

@evmar
Copy link
Contributor

evmar commented Feb 28, 2017

@evmar
Copy link
Contributor

evmar commented Feb 28, 2017

Note: someone tried to fix this before (in one of the above bugs) and their patch was dropped because the transforms branch changed everything. But this bug made it through the transforms branch!

@tbosch
Copy link
Contributor

tbosch commented Jun 15, 2017

Note that while working on the transfromer version of tsickle (see #516), I found that TypeScript does allow to emit comments in these places if they are added by a transformer (as a synthetic comment).

However, this breaks in some places in G3:

  • Closure warns when using this in expressions in ES6 string interpolations
  • Closure fails when doing the following:
export let ExtensibleError: ExtensibleErrorCtor = function(this: Error) {
  this.message = 'test'
} as any

tbosch added a commit to tbosch/tsickle that referenced this issue Jun 29, 2017
This is required by closure ES6 to not produce an error.

Note: In the current version of tsickle, type comments
in interpolations are elided because of angular#411. In the upcoming
transformer version, this is fixed though.
tbosch added a commit that referenced this issue Jun 30, 2017
This is required by closure ES6 to not produce an error.

Note: In the current version of tsickle, type comments
in interpolations are elided because of #411. In the upcoming
transformer version, this is fixed though.
@evmar
Copy link
Contributor

evmar commented Aug 20, 2019

Fixed.

@evmar evmar closed this as completed Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants