-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
TS 4.4.0-beta: #44624 change breaks existing code in CommonJS emit #45189
Comments
To be totally honest, the new behavior feels correct, but the reality is that this just breaks an unknown amount of existing code. |
The new behavior is correct, and I thought we did some kind of analysis to see how breaky it would be, but I canβt find that. It at least should be mentioned in the breaking changes section of the release notes (itβs missing from the beta notes). CC @DanielRosenwasser @rbuckton. |
Is it also Working as Intended that these two snippets have different behavior? import * as less from 'less';
less.render('input', () => {}); import {render} from 'less';
render('input', () => {}); |
I mean, itβs expected. The weird thing is that under the actual implemented CJS/ESM interop in Node v12+, neither of these will work. The only correct way to write an ESM import for this particular CJS module is |
For the record, in an actual native ESM implementation where |
Yeah, totally. The behavior seen in 4.4 looks completely expected, if you had some reason to believe that the receiver of |
Yeah I think the emit change is acceptable, but this should definitely be highlighted as a breaking change that affects the runtime. Most breaking changes just mean broken type checking, but given that this can break runtimes, and the type system won't catch it, I think it deserves bold lettering. |
The problem with Our emit now matches the emit of BabelJS, where you would also get an issue if you tried using |
Thatβs true to an extent, but AFAIK thereβs no way to change lessβs type definitions to make // @filename: node_modules/less/index.d.ts
declare class Less {
render(input: string): void;
}
declare const less: Less;
export = less;
// @filename: test.ts
import { render } from "less"; // no error
render(""); |
We could change the definition of |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
TS 4.4 beta commonjs
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
render
is called with athis
ofWindow
Emit is
π Expected behavior
render
is called with athis
ofrequire('less')
Emit should be
It looks like this was caused by #44624.
The text was updated successfully, but these errors were encountered: