Skip to content

Base constructor return type 'object' is not a class or interface type. #13975

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
kikar opened this issue Feb 9, 2017 · 8 comments
Closed

Base constructor return type 'object' is not a class or interface type. #13975

kikar opened this issue Feb 9, 2017 · 8 comments
Labels
Duplicate An existing issue was already created

Comments

@kikar
Copy link

kikar commented Feb 9, 2017

TypeScript Version: 2.2.0

Got this example from the 2.2 announcement

Code

export type Constructable = new (...args: any[]) => object;

export function Timestamped<BC extends Constructable>(Base: BC) {
    return class extends Base {
        timestamp = new Date();
    };
}

Expected behavior:
Extend my class with a timestamp.

Actual behavior:
Not compiling with error: "Base constructor return type 'object' is not a class or interface type."

@agubler
Copy link

agubler commented Feb 9, 2017

Using TS 2.2.0 (Release Candidate) the follow works as expected:

type Constructable = new (...args: any[]) => object;

function Timestamped<BC extends Constructable>(Base: BC) {
    return class extends Base {
        timestamp = new Date();
    };
}

class MyClass { }

const result = new (Timestamped(MyClass))();

// prints timestamp
console.log(result.timestamp);

@kikar
Copy link
Author

kikar commented Feb 9, 2017

Tried from scratch:

  • created an empty project
  • copied your code in index.ts
  • npm i -S typescript@rc
  • tsc index.ts

What I get is:

index.ts(4,26): error TS2509: Base constructor return type 'object' is not a class or interface type.

Do I need to add a tsconfig? Some special options?

@agubler
Copy link

agubler commented Feb 9, 2017

Are you sure that tsc is the version you have just installed? what if you install the release candidate globally and try the same thing?

@kikar
Copy link
Author

kikar commented Feb 9, 2017

npm ls -g --depth=0

└── typescript@2.2.0

npm ls --depth=0

└── typescript@2.2.0

Also, tried with both node v6.9.4 npm v3.10.10 and node v7.5.0 npm v4.1.2

@mhegazy
Copy link
Contributor

mhegazy commented Feb 9, 2017

This is a duplicate of #13805. The fix for this issue was not included in typescript@2.2.0, it should be included in the next release. typescript@next should already have the fix.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 9, 2017
@mhegazy mhegazy closed this as completed Feb 9, 2017
@agubler
Copy link

agubler commented Feb 9, 2017

Ha sorry I was actually using next! Apologies!

@kikar
Copy link
Author

kikar commented Feb 9, 2017

Why is it not going to be included in 2.2.0? Can you not make an rc1 that includes the fix?
The feature was already announced as part of 2.2.0

@mhegazy
Copy link
Contributor

mhegazy commented Feb 9, 2017

Why is it not going to be included in 2.2.0? Can you not make an rc1 that includes the fix?
The feature was already announced as part of 2.2.0

The next release is TS 2.2.1.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants