Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Circular reference error #787

Closed
hlz opened this issue Mar 23, 2021 · 1 comment
Closed

TypeScript Circular reference error #787

hlz opened this issue Mar 23, 2021 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@hlz
Copy link

hlz commented Mar 23, 2021

Describe the bug
Circular reference errors are thrown from TypeScript when using the Product entity in a local service class.

To Reproduce
Steps to reproduce the behavior:

  1. Create a clean install of Vendure
  2. Create a file with this code:
import {
	Injectable
} from '@nestjs/common';
import {
	CreateProductInput,
} from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';
import {
	Product,
	ProductTranslation,
	RequestContext,
} from '@vendure/core';

import { TranslatableSaver } from '@vendure/core/dist/service/helpers/translatable-saver/translatable-saver';

@Injectable()
export class TestImporterService {
	constructor(
		private translatableSaver: TranslatableSaver,
	) {
	}
	
	async createProduct(input: CreateProductInput): Promise<ID> {
		const product = await this.translatableSaver.create({
			ctx: RequestContext.empty(),
			input,
			entityType: Product,
			translationType: ProductTranslation,
			beforeSave: async () => {
				//
			},
		});
		
		return product.id;
	}
}
  1. See typescript errors appear

Expected behavior
I do not expect these errors to happen.

Environment (please complete the following information):

  • @vendure/core version: 1.0.0-beta.4
  • Nodejs version v14.15.2
  • Database (mysql/postgres etc): postgres

Additional context
See Slack's help channel for a discussion about this issue.

@hlz hlz added the type: bug 🐛 Something isn't working label Mar 23, 2021
@hlz
Copy link
Author

hlz commented Mar 23, 2021

Fwiw, the issue also happens in the Facet entity. In fact every entity that uses the Translation<T> type to reference itself has the issue. Think it all boils down to this line: https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/common/types/locale-types.ts#L39

When I remove the TranslatableKeys part from my local dist version everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants