Making instance via constructor property of another instance (TS2351: This expression is not constructable)

I need to instantiate some class which I have no access to. What I have is another instance of that class. In other words: the library does not export class, but its instance only, and I want to have another instance. The following code does solve the issue:

const myInstance = new importedInstance.constructor(params);

It works fine as pure javascript, but not as typescript. Typescript throws an error:

TS2351: This expression is not constructable. Type ‘Function’ has no construct signatures.

Is there any solution for typescript other than any-cast like new (importedInstance as any).constructor(params)?

53 thoughts on “Making instance via constructor property of another instance (TS2351: This expression is not constructable)”

  1. Hello there! This is my first visit to your blog! We are
    a group of volunteers and starting a new project in a community in the same niche.

    Your blog provided us useful information to work on. You have done a marvellous job!

    Reply
  2. Pingback: keto advanced
  3. Hey there! Someone in my Facebook group shared this website with
    us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers!
    Great blog and superb design and style.

    Reply
  4. It’s perfect time to make some plans for the future and it’s time to be happy.
    I have read this post and if I could I wish to suggest you some interesting things or suggestions.
    Maybe you can write next articles referring to this article.
    I desire to read more things about it!

    Reply
  5. I think this is among the most significant information for me.

    And i’m glad reading your article. But should remark on some general things, The web
    site style is wonderful, the articles is really nice : D.

    Good job, cheers

    Reply
  6. Do you have a spam issue on this blog; I also am a blogger, and I was wondering your situation; many of
    us have created some nice methods and we are looking to trade techniques with others, please shoot
    me an email if interested.

    Reply
  7. It’s the best time to make some plans for the future and it
    is time to be happy. I’ve read this post and if I could I desire
    to suggest you few interesting things or advice.
    Maybe you can write next articles referring to this article.
    I desire to read even more things about it!

    ps4 https://bit.ly/3z5HwTp ps4 games

    Reply