-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Bug
defineServerAuth requires as const on string literals in additionalFields and generateId even though the generic uses const R. Without it, types like 'string' widen to string and fail to match FieldType.
Repro
// Works
export default defineServerAuth(() => ({
advanced: { database: { generateId: 'uuid' as const } },
user: {
additionalFields: {
address: { type: 'string' as const, required: false, fieldName: 'address' },
},
},
}))
// Fails — TS2769: Type 'string' is not assignable to type 'FieldType'
export default defineServerAuth(() => ({
advanced: { database: { generateId: 'uuid' } },
user: {
additionalFields: {
address: { type: 'string', required: false, fieldName: 'address' },
},
},
}))Cause
The overload has <const R extends ServerAuthConfig> but ServerAuthConfig extends BetterAuthOptions which types deeply nested fields broadly (e.g. type: FieldType). For deeply nested properties the constraint wins over the const inference, so TypeScript widens the literal.
Suggestion
Narrow the generic to only infer the parts that matter (additionalFields, plugins, generateId) instead of constraining R against the full BetterAuthOptions. This way the const modifier can preserve literals without as const.
Version
@onmax/nuxt-better-auth v0.0.2-alpha.23
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels