-
Notifications
You must be signed in to change notification settings - Fork 109
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
Don't forward declare if googmodule is false #758
Conversation
Right, so the problem is that |
If we don't do Without |
Sorry I'm still learning TS so I don't quite follow -- why not? Which TS type declaration can't be represented either by a CC analog or |
Imagine you have this TS code: import {X} from 'x';
import {Y} from 'y';
function doSomethingWith(x: X) { return new Y(); }; TypeScript will emit something like: import {Y} from 'y';
function doSomethingWith(x) { return new Y(); }; Note how the import for Now if you change it to not emit forward declares, the code would look something like: import {Y} from 'y';
/**
* @param {??? what goes here ???} x
* @return {Y}
*/
function doSomethingWith(x) { return new Y(); }; And that's the problem that I don't know how to solve :-) |
Thanks for the explanation! So IIUC, tsickle isn't able to run the annotate transform because the type-only file has disappeared. How about the following?
I think status quo is not great since CC fully supports ES6 and there's no way to completely opt-out of |
@choumx I think the broken/missing piece here is that Closure does not have an equivalent of (1) would be possible, but currently the code just always uses the forward declared type when referencing types, so that'd complicate the code quite a bit. Can you explain what actual problem you're trying to fix here? Maybe there's an easier way? |
I think I'm still missing something. Why can't ES6 import replace In your example, let's imagine file // x.ts
export interface X {
foo: string;
} Expected output: // x.js
/** @record */
export function X() {}
/** @type {string} */
X.prototype.foo; // main.js
import {X} from 'x';
import {Y} from 'y';
/**
* @param {X} x
* @return {Y}
*/
function doSomethingWith(x) { return new Y(); }; Actual output: // main.js
const tsickle_forward_declare_1 = goog.forwardDeclare('path/to/x');
goog.require('path/to/x'); // force type-only module to be loaded
import {Y} from 'y';
/**
* @param {X} x
* @return {Y}
*/
function doSomethingWith(x) { return new Y(); }; |
The problem is our project's current build process doesn't play nicely with Closure modules. I could try fixing that instead, though I still don't quite understand why the "expected output" above is not feasible.
I saw this explanation in tsickle.js which sounds similar. Does ES6 import also exhibit the "load" behavior as Any clarification would be appreciated! |
The problem is that Also yes, by my understanding ES6 require will cause a load at runtime. |
Ok I see, you're comparing the behavior of TS -> JS with TS -> Closure-annotated JS. I see how this could be a problem for existing TS projects that want to add Closure Compiler by adopting tsickle. The thing is that our project doesn't care about TS -> JS behavior. We currently write Closure-annotated JS and existing code already performs runtime loads for "type-only" files -- as long as import order is preserved, behavior should not change. We just want to switch to TS just for the developer productivity benefit. How about a new configuration option to change this behavior for projects like ours? I think |
Sorry for the delay on this. Going to close this in favor of a new issue that clearly describes the FR. I'll try to find time to take this on but would also greatly appreciate help. 😄 |
Don't emit
goog.forwardDeclare
ifgoog.module
conversion is disabled.