• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to Use Sequelize Class in Front-end TypeScript Code

Resolved: How to Use Sequelize Class in Front-end TypeScript Code

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have my Sequelize models set up and working. Here’s a simplified example how how I’ve done it:
I want to be able to use the Thing data type throughout my app on both the front-end and back-end so that I get nice TypeScript support in VS Code for the properties available on my class.
But when I do this in my front-end code (which happens to be Svelte) I get a type error:
I also get crazy errors and behavior if I ever try and do this:
I'm relatively new to TypeScript and Sequelize. Am I not allowed to use my Thing class throughout my front and back-end JS?

Answer:

Sequelize wants access to the database (via NodeJS api's) and is not available in the Frontend.
A type import: import type { Thing } from "$lib/db"; should be allowed, this statement is removed after typescript compilation.
But is it only for type checking, and because real class can't be used it's not very useful.

If you have better answer, please add a comment about this, thank you!

sequelize.js svelte sveltekit typescript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Best way to create 3d matrix of variables in PULP

24/03/2023

Resolved: Openlayers: Update clusters depending on filter (geometryFunction)

24/03/2023

Resolved: Getting ‘502 Bad Gateway’ while deploying Springboot app in EKS

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.