You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use generic class in the TSX file and generic class is implemented in the another module. I have tried to use code like in the #3960 (comment) but it doesn't work because old style casting is not allowed in the TSX file. Ok, I have changed it to the as operator but it emits incorrect code. It refers to the generic class directly without using require.
After that I have created simple example without JSX which demonstrates that old style casting and as operator are different.
File generic.ts: export default class Generic<T> {}
File sample.ts:
import Generic from "./generic";
type Ctor = new() => Generic<number>;
const x = Generic as Ctor;
Compile tsc sample.ts --module commonjs. Result:
var generic_1 = require("./generic");
var x = Generic;
As you see generic_1 variable isn't used at all and undeclared Generic variable is assigned to x.
Workaround:
import Generic from "./generic";
type Ctor = new () => Generic<number>;
const x = Generic;
const y = x as Ctor;
Also please note that using old-style casting also helps:
import Generic from "./generic";
type Ctor = new() => Generic<number>;
const x = <Ctor>Generic;
So it looks like it is the problem in the as operator only.
The text was updated successfully, but these errors were encountered:
I'm trying to use generic class in the TSX file and generic class is implemented in the another module. I have tried to use code like in the #3960 (comment) but it doesn't work because old style casting is not allowed in the TSX file. Ok, I have changed it to the
as
operator but it emits incorrect code. It refers to the generic class directly without usingrequire
.After that I have created simple example without JSX which demonstrates that old style casting and
as
operator are different.File generic.ts:
export default class Generic<T> {}
File sample.ts:
Compile
tsc sample.ts --module commonjs
. Result:As you see generic_1 variable isn't used at all and undeclared
Generic
variable is assigned tox
.Workaround:
Also please note that using old-style casting also helps:
So it looks like it is the problem in the
as
operator only.The text was updated successfully, but these errors were encountered: