You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { SimpleService } from '@/services/simple-service.ts';
import { injectable } from 'tsyringe';
@injectable()
export class X {
constructor(s: SimpleService) {}
}
and a class Y:
import { SimpleService } from '../services/simple-service.ts';
import { injectable } from 'tsyringe';
@injectable()
export class Y {
constructor(s: SimpleService) {}
}
import { singleton } from 'tsyringe';
@singleton()
export class SimpleService {
constructor() {}
}
tsconfig.json
{
...
"paths": { "@/*": [ "src/*" ] }
}
Than X and Y load their own class SimpleService. This is problematic, if you use dependency injection, i.e. with tsyringe (@singleton()), or other Constructor-related Type token things, because now the Type class SimpleService just exists two times at runtime. I think it's not related to tsyringe, because the registration-key is just the class-Type. Other frameworks will fail similarly.
If you either always use the relative imports or always the absolute imports, just one loaded class exists at runtime.
Hence tsconfig-paths is probably doing something wrong. Both imports must lead to same loaded class at runtime.
The text was updated successfully, but these errors were encountered:
Imagine you have a class X:
and a class Y:
tsconfig.json
Than
X
andY
load their own classSimpleService
. This is problematic, if you use dependency injection, i.e. withtsyringe
(@singleton()
), or other Constructor-relatedType
token things, because now the Typeclass SimpleService
just exists two times at runtime. I think it's not related totsyringe
, because the registration-key is just the class-Type. Other frameworks will fail similarly.If you either always use the relative imports or always the absolute imports, just one loaded class exists at runtime.
Hence
tsconfig-paths
is probably doing something wrong. Both imports must lead to same loaded class at runtime.The text was updated successfully, but these errors were encountered: