Typescript Enum array raises CircularDependencyError
See original GitHub issueI’m submitting a…
[ ] Regression
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
using an enum array in a typescript object causes this error:
Error: A circular dependency has been detected (property key: "roles").
Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
not the same, but maybe related to #507
Expected behavior
no error
Minimal reproduction of the problem with instructions
GitHub Repository to reproduce the issue.
- clone the repo
npm install
npm run start:api
See file: create-cat.dto.ts
export class CreateCatDto {
readonly name: string;
readonly age: number;
readonly breed: string;
/**
* using an enum array causes this exception:
*
* Error: A circular dependency has been detected (property key: "roles").
* Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
*/
readonly roles: RoleEnum[];
}
Environment
Nest version: 7.4.2
For Tooling issues:
- Node version: 14.3.0
- Platform: Windows 10 64-bit
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Convert a typescript enum into an array of enums
1. I want to retain the type as enum. · 3. I believe you can use Object. · 6. Element implicitly has an...
Read more >TypeScript enums vs. types for writing readable code
Enums allow us to define or declare a collection of related values that can be numbers or strings as a set of named...
Read more >Convert a TypeScript Enum to a JavaScript Array or String
Converting a TypeScript Enum to a JavaScript Array is pretty easy, and I often use it to fill a <select> with all the...
Read more >Enums in TypeScript - George Marklow - Medium
An enum is a set of labeled values called members and is used to organize a group of similar values. A typical data...
Read more >Should You Use Enums or Union Types in Typescript?
While using TypeScript, there's something that we need to do quite often: define ... Can't iterate over a type, defining an array is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Follow-up: I managed to workaround the issue using this comment:
@tmtron I looked at your repo and was able to run with the following changes:
I don’t know where you get
type: () => [RoleEnum]
from forenum
field. That syntax is specifically for nested classes. Can you make that same change in your code to see if it works?