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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With