You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Contentrain Nuxt JSON readme update and playground fix
- Playground için otomatik olarak oluşturulan tür tanımlarını kaldırma
- İçe aktarılan tür tanımlarını `#build/types/contentrain` olarak güncelleme
- Gereksiz bağımlılıkları `package.json` ve `pnpm-lock.yaml`'den çıkarma
- Sayfa bileşenlerinde tür güvenliğini ve veri erişimini iyileştirme
For full TypeScript integration, define your content types:
234
+
### Automatic Type Generation
235
+
236
+
The module automatically generates TypeScript types from your content models during the build process. These types are available in your project via the `#build/types/contentrain` import path:
237
+
238
+
```ts
239
+
// Import automatically generated types
240
+
importtype { Post, Author, Category } from'#build/types/contentrain'
241
+
242
+
// Use the types in your queries
243
+
const query =useContentrainQuery<Post>('posts')
244
+
```
245
+
246
+
The generated types include:
247
+
- All model properties with correct types
248
+
- Relation properties with proper typing
249
+
- Multilingual support with language-specific types
250
+
- Full IntelliSense support in your IDE
251
+
252
+
### Manual Type Definitions
253
+
254
+
You can also define your content types manually if needed:
233
255
234
256
```ts
235
257
// types/content.ts
@@ -266,12 +288,12 @@ The main composable for querying content.
266
288
-`modelId`: Model ID
267
289
268
290
**Methods:**
269
-
-`where(field, operator, value)`: Adds a filter
270
-
-`orderBy(field, direction)`: Adds a sort
291
+
-`where(field, operator, value)`: Adds a filter with type-safe field and value checking
292
+
-`orderBy(field, direction)`: Adds a sort with type-safe field checking
271
293
-`limit(limit)`: Limits the number of results
272
294
-`offset(offset)`: Sets the starting index
273
-
-`include(relation)`: Includes a relation
274
-
-`locale(locale)`: Sets the language
295
+
-`include(relation)`: Includes a relation with type-safe relation checking
296
+
-`locale(locale)`: Sets the language with type-safe locale checking (only accepts valid locales defined in your model)
275
297
-`get()`: Executes the query and returns the results
276
298
-`first()`: Returns the first result
277
299
-`count()`: Returns the total count
@@ -593,6 +615,36 @@ Query parameters are invalid.
593
615
594
616
**Solution:** Ensure that your query parameters are in the correct format.
595
617
618
+
### TypeScript Errors
619
+
620
+
#### `Argument of type 'string' is not assignable to parameter of type 'never'`
621
+
622
+
This error occurs when using the `locale()` method with a locale that is not defined in your model.
623
+
624
+
**Solution:** Make sure you're using a locale that is defined in your model's `_lang` property. For example, if your model only supports 'en' and 'tr', you can only use these values with the `locale()` method.
625
+
626
+
```ts
627
+
// Correct usage
628
+
query.locale('en') // Works if 'en' is defined in your model
629
+
query.locale('tr') // Works if 'tr' is defined in your model
630
+
631
+
// Incorrect usage
632
+
query.locale('fr') // TypeScript error if 'fr' is not defined in your model
633
+
```
634
+
635
+
#### `Property '_relations' does not exist on type...`
636
+
637
+
This error occurs when trying to access relations on a model that doesn't have any defined relations.
638
+
639
+
**Solution:** Make sure your model has relations defined in its schema, or check if the relation is properly included in your query using the `include()` method.
640
+
641
+
```ts
642
+
// Make sure to include the relation before accessing it
643
+
const query =useContentrainQuery<Post>('posts')
644
+
.include('author')
645
+
.get()
646
+
```
647
+
596
648
## Contributing
597
649
598
650
We welcome your contributions! Please read our [contribution guidelines](CONTRIBUTING.md).
0 commit comments