Search code examples
typescriptwebstormsystemjsdefinitelytyped

systemjs.d.ts has compilation errors regarding type aliases


I added the file systemjs.d.ts (definitely typed of System.js) to WebStorm IDE, and I get two errors in this file (which are the same).

These are the error lines:

type ModuleFormat = "esm" | "cjs" | "amd" | "global" | "register";

type Transpiler = "traceur" | "babel" | "typescript";

I've read about the "type" keyword which means aliases, but couldn't find any example in which they use strings like here, but only types. So I guess it's a bug in the file.

The error I get:

TS1110: Type expected

The whole systemjs.d.ts file: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/systemjs/systemjs.d.ts

Is this a bug in the file? How could I fix it?

Any help will be profoundly appreciated!


Solution

  • This is a union of string literal types, it means that a variable of type ModuleFormat can only have one of the specified values.

    This feature is new in typescript 1.8, could it be that you're getting an error because you're compiling with an older version of typescript?

    See this example:

    type Answer = "yes" | "no" | "maybe";
    
    function question(response: Answer) { }
    
    question("yes"); // OK
    question("sure"); // Error