Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type import().Client is not assignable to parameter of type import().Client

I have two modules:

In one module I reference a function from another module run:

@myorg/server

import { Client } from '.'
import { Middleware } from '@myorg/middleware'

let client = new Client()
Middleware.run(client)

Then in the other module I reference only a type like this:

@myorg/middleware

// References a '.d.ts' file
import { Client } from '@myorg/server'

export class Middleware {

  public run(client: Client){
    // Do some stuff
  }

}

When I have this setup, Middleware.run(client) gives me the following error:

Argument of type 'import("/framework/server/src/Client").Client' is not assignable to parameter of type 'import("/framework/server/types/Client").Client'.

As the error points out src (the actual code) and types (the .d.ts file) are not compatible. What is causing this and how can I fix it?

like image 535
Get Off My Lawn Avatar asked Oct 16 '22 16:10

Get Off My Lawn


1 Answers

You should also import the type Client in @myorg/middleware from the same source file that @myorg/server imports it from.

Explanation: In @myorg/middleware you are importing the type Client from a type declaration file (.d.ts) which I assume you have referenced it on top of the file with a /// directive. Whereas in the @myorg/server that Client type is directly imported from the actual source code. Therefore Typescript does not consider those two as the same and that's why you get this error.

like image 59
J. Koutsoumpas Avatar answered Oct 20 '22 15:10

J. Koutsoumpas