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

QN typeguard for relation loading #492

Open
ondratra opened this issue May 25, 2022 · 0 comments
Open

QN typeguard for relation loading #492

ondratra opened this issue May 25, 2022 · 0 comments
Assignees
Labels

Comments

@ondratra
Copy link
Contributor

Sometimes we encounter a hardly spotted bug in the mappings when we rely on some relation being loaded that is actually not loaded.

// invalid case
const video = await store.get(Video, { where: { id: SomeId } })
console.log(video.channel) // undefined; 

// valid case
const video = await store.get(Video, { where: { id: SomeId }, relations: ['channel'] })
console.log(video.channel)

As shown in the example, if a developer forgets to add relations: ['myEntity'] and then tries to access it, the error occurs. Currently, this is not caught by a compiler.

Let's try to improve our Typescript type guards for DatabaseManager so that .get and other methods return type that signals what relations are actually loaded and triggers compilation errors when not-loaded relations are used.

@ondratra ondratra added the enhancement New feature or request label May 25, 2022
@ondratra ondratra self-assigned this May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants