Skip to content

Cannot use properties as types #2732

Open
@jplaisted

Description

@jplaisted
class Parent {}
const Obj = {};
Obj.Alias = Parent;
class Child extends Obj.Alias {} // Bad type annotation. Unknown type Obj.Alias

Link

The error here stems from the @extends {Obj.Alias} in the transpiled code.

This causes a bug in ES6 module rewriting. If a class is exported directly then things are fine:

export class Parent {
  static staticFunction() { return 'Parent.staticFunction'; }
}
import { Parent } from './input0';
class Child extends Parent {}

Link

Note the type annotation of the extends ends up being Parent$$module$input0.

But if we export using export specs there's an error.

class Parent {
  static staticFunction() { return 'Parent.staticFunction'; }
}
export  { Parent };
import { Parent } from './input0';
class Child extends Parent {} // Bad type annotation. Unknown type module$input0.Parent

Link

Note the type annotation is now module$input0.Parent.

Appears to be an OTI only bug, but seems pretty important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions