Skip to content

Types declaration on "Static" members of a function are invalid #31882

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

Closed
alexandcote opened this issue Jun 12, 2019 · 0 comments · Fixed by #31971
Closed

Types declaration on "Static" members of a function are invalid #31882

alexandcote opened this issue Jun 12, 2019 · 0 comments · Fixed by #31971
Assignees
Labels
Bug A bug in TypeScript

Comments

@alexandcote
Copy link

alexandcote commented Jun 12, 2019

Typescript generates invalid declaration when you declare a "static" element on a function and the name of this "static" element is exactly the same on the other side of the equality. Hard to explain but a small example below demonstrate the issue.

Note, this issue only happens when you add a function or a class as a "static" element of a function.

TypeScript Version: 3.6.0-dev.20190612

Search Terms:

'X' is referenced directly or indirectly in its own type annotation.

Code

import {Foo} from './foo';
export default function Example() {
    console.log("Example 2");
}
Example.Foo = Foo

Temporary Solution

import {Foo as DifferentNameFoo} from './foo';
export default function Example() {
    console.log("Example 2");
}
Example.Foo = DifferentNameFoo

Expected behavior:

import { Foo as GenericFoo } from './foo';
declare function Example(): void;
declare namespace Example {
    var Foo: typeof GenericFoo;
}
export default Example;

The expected behaviour is tricky because if you export in the same file Foo you have another issue.

A solution could be:

import { Foo as GenericFoo } from './foo';
export { GenericFoo as Foo };
declare function Example(): void;
declare namespace Example {
    var Foo: typeof GenericFoo;
}
export default Example;

Again another issue if Foo is a function in the same file.

Actual behaviour:

import { Foo } from './foo';
declare function Example(): void;
declare namespace Example {
    var Foo: typeof Foo;
}
export default Example;

Playground Link:
Go see this repo for more examples.
https://github.com/alexandcote/typescript-example

@alexandcote alexandcote changed the title Types declaration on "Static" member of function are invalid Types declaration on "Static" member of a function are invalid Jun 12, 2019
@alexandcote alexandcote changed the title Types declaration on "Static" member of a function are invalid Types declaration on "Static" members of a function are invalid Jun 12, 2019
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 17, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.0 milestone Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
3 participants