Skip to content

Commit 58d7300

Browse files
Merge pull request nestjs#1248 from andrew-yustyk/issue/1246
fix(core/common): allow to use symbol token in the module exports
2 parents f71613a + 644b2c1 commit 58d7300

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

packages/common/utils/shared.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export const validatePath = (path): string =>
88
path.charAt(0) !== '/' ? '/' + path : path;
99
export const isNil = (obj): boolean => isUndefined(obj) || obj === null;
1010
export const isEmpty = (array): boolean => !(array && array.length > 0);
11-
export const isSymbol = (fn): boolean => typeof fn === 'symbol';
11+
export const isSymbol = (fn): fn is symbol => typeof fn === 'symbol';

packages/core/injector/module.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Module {
4747
private readonly _components = new Map<any, InstanceWrapper<Injectable>>();
4848
private readonly _injectables = new Map<any, InstanceWrapper<Injectable>>();
4949
private readonly _routes = new Map<string, InstanceWrapper<Controller>>();
50-
private readonly _exports = new Set<string>();
50+
private readonly _exports = new Set<string | symbol>();
5151

5252
constructor(
5353
private readonly _metatype: Type<any>,
@@ -82,7 +82,7 @@ export class Module {
8282
return this._routes;
8383
}
8484

85-
get exports(): Set<string> {
85+
get exports(): Set<string | symbol> {
8686
return this._exports;
8787
}
8888

@@ -279,14 +279,14 @@ export class Module {
279279
}
280280

281281
public addExportedComponent(
282-
exportedComponent: ComponentMetatype | string | DynamicModule,
282+
exportedComponent: ComponentMetatype | string | symbol | DynamicModule,
283283
) {
284-
const addExportedUnit = (token: string) =>
284+
const addExportedUnit = (token: string | symbol) =>
285285
this._exports.add(this.validateExportedProvider(token));
286286

287287
if (this.isCustomProvider(exportedComponent as any)) {
288288
return this.addCustomExportedComponent(exportedComponent as any);
289-
} else if (isString(exportedComponent)) {
289+
} else if (isString(exportedComponent) || isSymbol(exportedComponent)) {
290290
return addExportedUnit(exportedComponent);
291291
} else if (this.isDynamicModule(exportedComponent)) {
292292
const { module } = exportedComponent;
@@ -305,7 +305,7 @@ export class Module {
305305
this._exports.add(this.validateExportedProvider(provide.name));
306306
}
307307

308-
public validateExportedProvider(token: string) {
308+
public validateExportedProvider(token: string | symbol) {
309309
if (this._components.has(token)) {
310310
return token;
311311
}
@@ -316,7 +316,7 @@ export class Module {
316316
.filter(metatype => metatype)
317317
.map(({ name }) => name);
318318

319-
if (!importedRefNames.includes(token)) {
319+
if (!importedRefNames.includes(token as any)) {
320320
const { name } = this.metatype;
321321
throw new UnknownExportException(name);
322322
}

0 commit comments

Comments
 (0)