-
-
Notifications
You must be signed in to change notification settings - Fork 127
Closed
Labels
Milestone
Description
Description and expected behavior
Typescript asks for delegation field when creating new polymorphic instance when providing id with a default of auto increment.
Steps to reproduce
pnpm initpnpm i -D typescriptnpx tsc --initnpx zenstack init- Copy paste the following models to your schema:
model Post {
id Int @id @default(autoincrement())
name String
type String
@@delegate(type)
// full access by author
@@allow('all', true)
}
model ConcretePost extends Post {
age Int
}
- Run
npx zenstack generate && npx prisma migrate dev --name "update" - Create index.ts file at root and copy paste the following content:
import { PrismaClient as Prisma } from "@prisma/client";
import { enhance } from "@zenstackhq/runtime";
const prisma = new Prisma()
const db = enhance(prisma, {}, {
kinds: ['delegate']
})
async function main() {
const newPost = await db.concretePost.create({
data: {
id: 5,
name: 'a name',
age: 20
}
})
const posts = await db.post.findMany({})
console.log('posts', posts)
}
main()Now you will see that typescript shouts on data saying that type field is missing.
Btw if you execute this code (You can run on terminal npx tsx index.ts) it will work just fine.
Environment (please complete the following information):
"devDependencies": {
"prisma": "^5.20.0",
"typescript": "^5.6.2",
"zenstack": "2.6.2"
},
"dependencies": {
"@prisma/client": "^5.20.0",
"@zenstackhq/runtime": "2.6.2"
}
