Skip to content

Commit

Permalink
Merge pull request #13370 from nestjs/revert-13056-perf/12914-readabl…
Browse files Browse the repository at this point in the history
…e-error-on-undefined-token

Revert "perf(common): Improve error handling for undefined tokens"
  • Loading branch information
kamilmysliwiec committed Mar 28, 2024
2 parents 1f2fae7 + 8a4166a commit 5596729
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
6 changes: 0 additions & 6 deletions packages/common/decorators/core/inject.decorator.ts
Expand Up @@ -39,12 +39,6 @@ export function Inject<T = any>(
return (target: object, key: string | symbol | undefined, index?: number) => {
const type = token || Reflect.getMetadata('design:type', target, key);

if (!type) {
throw new Error(`Token is undefined at index: ${index}. This often occurs due to circular dependencies.
Ensure there are no circular dependencies in your files or barrel files.
For more details, refer to https://trilon.io/blog/avoiding-circular-dependencies-in-nestjs.`);
}

if (!isUndefined(index)) {
let dependencies =
Reflect.getMetadata(SELF_DECLARED_DEPS_METADATA, target) || [];
Expand Down
10 changes: 0 additions & 10 deletions packages/common/test/decorators/inject.decorator.spec.ts
Expand Up @@ -22,14 +22,4 @@ describe('@Inject', () => {
];
expect(metadata).to.be.eql(expectedMetadata);
});

it('should throw an error when token is undefined', () => {
const defineInvalidClass = () => {
class Test {
constructor(@Inject(undefined) invalidParam) {}
}
};

expect(defineInvalidClass).to.throw(/^Token is undefined/);
});
});

0 comments on commit 5596729

Please sign in to comment.