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

Defining models guide for typescript? (Error: "Property 'id' has no initializer and is not definitely assigned in the constructor.") #1361

Closed
mfbx9da4 opened this issue Jul 28, 2022 · 3 comments

Comments

@mfbx9da4
Copy link
Contributor

mfbx9da4 commented Jul 28, 2022

Hi, I'm new to watermelonDB but having trouble defining my model. There doesn't seem to be a typescript guide. For a start you need to enable experimentalDecorators in tsconfig which doesn't seem to be documented.

I am currently facing the error "Property 'id' has no initializer and is not definitely assigned in the constructor."

import { Model } from '@nozbe/watermelondb'
import { field, text, date } from '@nozbe/watermelondb/decorators'

export default class Me extends Model {
  static table = 'me'
  @text('id') id: string // ❌ throws error "Property 'id' has no initializer and is not definitely assigned in the constructor."
}
@mfbx9da4 mfbx9da4 changed the title Defining models documentation for typescript - Error "Property 'id' has no initializer and is not definitely assigned in the constructor." Defining models guide for typescript? (Error: "Property 'id' has no initializer and is not definitely assigned in the constructor.") Jul 28, 2022
@mfbx9da4
Copy link
Contributor Author

mfbx9da4 commented Jul 28, 2022

I found this typescript example https://github.com/Nozbe/WatermelonDB/blob/master/examples/typescript/ts-example.ts

Also the id column is a reserved special field https://nozbe.github.io/WatermelonDB/Schema.html#special-columns

Above example should look more like this

import { Model } from '@nozbe/watermelondb'
import { field, text, date } from '@nozbe/watermelondb/decorators'

export default class Me extends Model {
  static table = 'me'
  @text('firstName') firstName!: string | null
}

@mfbx9da4 mfbx9da4 reopened this Jul 28, 2022
@mfbx9da4
Copy link
Contributor Author

mfbx9da4 commented Jul 28, 2022

Reopening because there is no link to this example in the documentation. Also documentation for withObservables with typescript would be great too!

@radex
Copy link
Collaborator

radex commented Feb 3, 2023

Closing for now to consolidate it to these issues:

#1516

#1481

@mfbx9da4 your contributions to docs would be highly appreciated

@radex radex closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants