-
Notifications
You must be signed in to change notification settings - Fork 12.8k
"Expando assingment" for Javascript namespace stopped working. #49944
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
@mpawelski I just tested with v4.7.3 and it worked (compiled with no error) and this is the resulting JS file: app.foo.bar = (function () {
var someFun = function (arg) { };
return { someFun: someFun };
})();
app.foo.bar.someFun(1); |
@babakks |
@RyanCavanaugh I tried to debug/compare on both the current dev (v4.8) and v4.4.2. At last, it seems like the problem has something to do with the function getContextualReturnType(functionDecl: SignatureDeclaration, contextFlags: ContextFlags | undefined): Type | undefined {
// ...
const iife = getImmediatelyInvokedFunctionExpression(functionDecl);
if (iife) {
return getContextualType(iife, contextFlags);
}
// ...
} When the control reaches this, To confirm this I introduced a new parameter to the @mpawelski One workaround for this, though I'm sure you've already found that, is to separate the function definition and the invocation like this: declare namespace app {
function foo(): void;
}
function expand() {
const someFun = (arg: number) => { };
return { someFun };
}
app.foo.bar = expand();
app.foo.bar.someFun(1); |
It's not related to IIFE, a simple object literal have the same error. playground declare namespace app {
function foo(): void;
}
// 'bar' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
app.foo.bar = {
someFun(arg: number) {}
};
app.foo.bar.someFun(1); |
Looks that the "declare a namespace with a function inside and expand the function with expando assignments" workaround for my "JS namespaces" stopped working in TS 4.5
💻 Code
This works in 4.4.2.
This doesn't work in 4.5.5
🙁 Actual behavior
Compiler error:
🙂 Expected behavior
No error with proper inference.
The text was updated successfully, but these errors were encountered: