Skip to content
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

Type 'any' is not a constructor function type #4582

Closed
weswigham opened this issue Sep 1, 2015 · 3 comments
Closed

Type 'any' is not a constructor function type #4582

weswigham opened this issue Sep 1, 2015 · 3 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@weswigham
Copy link
Member

class Thing extends ((function () {
    return null;
})()) {
    doThing() {
    }
}

It's a really roundabout way to say extends null, but the types don't check out, which is awkward. You have to annotate the IIFE with a dummy ctor type like StringConstructor to satisfy the checker.

@mhegazy mhegazy added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Sep 3, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 3, 2015

This is by design. the only supported form of extending null is extends null anything else, has to return a value whose type has a construct signature. We have excluded any as a wildcard in this scenario, just because it is more likely a user error here than intended. it would be interesting to see if there are actual use cases where this would be needed.

@mhegazy mhegazy closed this as completed Sep 3, 2015
@amcdnl
Copy link

amcdnl commented Jul 12, 2016

Here is an interesting case, in TypeScript 2.0 I declare a module swagger-client like:declare module 'swagger-client';. However, when I try to use it like:

import * as Swagger from 'swagger-client';

class Swagger extends Swagger {
  pet: any;
  constructor() {
    super({ 
      url: config.get('spec.petstore'),
      usePromise: true
    });
  }
}

I get the error Type 'any' is not a constructor function type.

@JohnnyClutch
Copy link

JohnnyClutch commented Oct 31, 2016

I got this error when I imported from index file like so:

import {Derived, Base} from '.'

and the derived class was listed in index.ts before the base class:

export {Derived} from './Derived';
export {Base} from './Base';

I switched the order and it worked.

@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
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

4 participants