-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Missing --isolatedModules error for type referenced by decorator metadata #42281
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
Comments
This bug is specifically about
|
@andrewbranch thanks for updating the ticket and making it more clear :-) |
I ambiguous imports with __decorate([
EventListener('gEvent'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [typeof (_a = typeof IGEvent !== "undefined" && IGEvent) === "function" ? _a : Object]),
__metadata("design:returntype", void 0)
], HelloWorld.prototype, "_handleEvent", null); The problem is that we're not rewriting the We possibly should be rewriting this to be the following instead: var _a;
import { Component, EventListener, GondelBaseComponent } from '@gondel/core';
import * as types_1 from './types';
let HelloWorld = class HelloWorld extends GondelBaseComponent {
_handleEvent(event) {
alert(event.data.eventData.helloWorld);
}
};
__decorate([
EventListener('gEvent'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [typeof (_a = typeof types_1.IGEvent !== "undefined" && types_1.IGEvent) === "function" ? _a : Object]),
__metadata("design:returntype", void 0)
], HelloWorld.prototype, "_handleEvent", null);
HelloWorld = __decorate([
Component('HelloWorld')
], HelloWorld); This way, if there is a value for |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
Typescript is not throughing an error for Type imports not having the keyword
import type
from Files containing only type exports, when havingisolatedModules
set totrue
.🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
See attached Zip Code and Readme.md for instructions.
💻 Code
The types.ts files contains only named exports
The index.ts imports the event interface and uses it within it's decorated method signature
The used library gondel is a component framework to start components on a page and handle their lifecycle.
The warning goes away when
Code Example.zip
🙁 Actual behavior
When using Webpack, it throughs a build-breaking error since Webpack 5, before, a warning was shown.
When just using native TS for Compiling, I don't get an Error.
🙂 Expected behavior
Courtesy of explanation goes to @andrewbranch, see Ticket #40420.
The point of isolatedModules is to tell you ahead of time if a transpiler (like Babel or ts-loader in transpile mode) will not have enough information to know whether the code it produces at runtime is safe or not. That’s what’s happening here—ts-loader in transpile mode cannot possibly know whether IGEvent has a value meaning by only looking at index.ts, and so it stays in. Webpack is smart enough to detect this and tell you about it, and prior to v5, forgiving enough to fix up your runtime code. But at the core, what happened was you wrote something that could not be analyzed by ts-loader, and consequently ts-loader produced fundamentally broken output. isolatedModules is the way you tell the compiler that you’re going to use a transpiler, and so you want errors that prevent you from getting in this situation.
The text was updated successfully, but these errors were encountered: