Typescript Compiler Error "Generic type requires 0 type argument(s)"

typescript

Solution

This looks like a compiler bug - the compiler isn't realising that you are trying to use the class named `SomeClass` rather than the module named `SomeClass`.

The good news is that your declaration is actually good and the next version of the compiler (0.9.5) will be perfectly happy with it.

You can download the 0.9.5 beta, which has some bug fixes and performance improvements (but is obviously a beta... but I'm using it and it seems stable).

Problem

(This is a follow up to this answer.) I am trying to build a typescript definition file for an existing Javascript library. The difficulties I have are related to the combination of: - nested types - generics - named constructors (which are very similar to nested types) This is the code I'm trying to compile in a `lib.d.ts` library defintion file: ``` declare module MyModule { export class SomeClass<T> { new(); // default (unnamed) constructor for SomeClass static WithEnumValue: { // "named constructor" for SomeClass new <T>(enumValue: MyModule.SomeClass.SomeEnum): SomeClass<T>; }; } export module SomeClass { export enum SomeEnum { VALUE_A, B, C } } } declare module OtherModule { export interface OtherInterface { foo<T>(inst: MyModule.SomeClass<T>); } } ``` The problem is the declaration of the generic method `foo` in the `OtherModule.OtherInterface` Using the above code I get this strange compiler output (using tsc compiler 0.9.1.1): `error TS2090: Generic type 'MyModule.SomeClass' requires 0 type argument(s).` Obviously it is hard to declare a generic type with 0 type arguments, because neither `<>` nor the variant without type arguments `MyModule.SomeClass` will work - the latter will give this slightly contradicting error: `error TS2173: Generic type references must include all type arguments.` I can get it to compile if I declare the `OtherInterface` inside `MyModule` and leave away the module name, but the interface is in a different module in the real world. How can I get this to work properly?

Original source