drizzle-team / drizzle-team/drizzle-orm
[FEATURE]:When I use $type, selectSchema.array().parse and insertSchema.safeParse doesn't get the correct type.
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
```tsx
// App.tsx
import { integer, sqliteTable } from 'drizzle-orm/sqlite-core'
import { createSelectSchema, createInsertSchema } from 'drizzle-zod'
import { openDatabaseSync } from 'expo-sqlite'
import { drizzle } from 'drizzle-orm/expo-sqlite'
import React, { useState } from 'react'
type TUpdateWeekday = 1 | 2 | 3 | 4 | 5 | 6 | 7
export const table = sqliteTable('table', {
updateWeekday: integer('update_weekday').$type().notNull(),
})
export const selectSchema = createSelectSchema(table)
function isTUpdateWeekday(value: number): value is TUpdateWeekday {
return value >= 1 && value <= 7 && Number.isInteger(value)
}
const insertSchema = createInsertSchema(table, {
updateWeekday: (schema) => schema.refine((val) => isTUpdateWeekday(val)),
})
const expo = openDatabaseSync('db.db')
const db = drizzle(expo)
function App() {
type TData = typeof table.$inferSelect
type TInput = typeof table.$inferInsert
const b: any = 2
const a: TInput = {
updateWeekday: b,
}
const result = insertSchema.safeParse(a)
if (result.success) {
console.log(result.data)
db.insert(table).values(result.data)
} else {
console.log(result.error)
}
const [list, setList] = useState([])
async function init() {
const row = await db.select().from(table)
const parseRow = selectSchema.array().parse(row)
setList(parseRow)
}
return
}
export default App
```





I need to use type assertion to resolve this issue.


Contributor guide
Assessment
This issue has not been assessed yet.