Organization plugin gives type error:

I get the following type-error when adding the organization plugin to my better-auth server client.
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; metadata?: Record<string, any> | undefined; userId?: string | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'schema' are incompatible.
Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'.
Property 'team' is incompatible with index signature.
Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.
Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; metadata?: Record<string, any> | undefined; userId?: string | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'schema' are incompatible.
Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'.
Property 'team' is incompatible with index signature.
Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.
Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'
19 Replies
Nextify
Nextify4mo ago
same error
crthub
crthub4mo ago
hey @Nextify. pull request already open - https://github.com/better-auth/better-auth/pull/3084. waiting for merge->release. Till than, you can patch fix this issue.
Nextify
Nextify4mo ago
Thank you very much for your response. Do you have plans to merge it into the next version?
Gabriel Augusto
Gabriel Augusto4mo ago
I had the same problem, I solved it this way, apparently it's just a problem with typing, not with functionality: organization({ allowUserToCreateOrganization: true, teams: { enabled: true, }, ac, roles: organizationRoles, }) as import('better-auth').BetterAuthPlugin, // Type assertion
Esscraye
Esscraye4mo ago
is it merged ? i still have that issue too
Ping
Ping4mo ago
Hey can I see your tsconfig?
Esscraye
Esscraye3mo ago
i used what said Gabirel and works fine, but sure i can show you my tsconfig file :
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
}
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
}
Ping
Ping3mo ago
I really don't recommend following that advice since it means you lose ts inference for all of the organization endpoints. Try disabling declaration and declarationMap
Tim Reynolds
Tim Reynolds3mo ago
I tried following the docs to add the Organization pluging today and get the following typescript error;
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; metadata?: Record<string, any> | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'schema' are incompatible.
Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'.
Property 'team' is incompatible with index signature.
Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.
Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.ts(2322)
Type '{ id: "organization"; endpoints: { createOrganization: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: { body: { name: string; slug: string; userId?: string | undefined; metadata?: Record<string, any> | undefined; logo?: string | undefined; keepCurrentActiveOrganization?: bo...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'schema' are incompatible.
Type '{ team?: { modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined; ...' is not assignable to type 'AuthPluginSchema'.
Property 'team' is incompatible with index signature.
Type '{ modelName: string | undefined; fields: { name: { type: "string"; required: true; fieldName: string | undefined; }; organizationId: { type: "string"; required: true; references: { model: string; field: string; }; fieldName: string | undefined; }; createdAt: { ...; }; updatedAt: { ...; }; }; } | undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.
Type 'undefined' is not assignable to type '{ fields: { [x: string]: FieldAttribute<FieldType>; }; disableMigration?: boolean; modelName?: string; }'.ts(2322)
This is without passing anything into the function, so no options. I'm using the drizzle adapter if that is related
Tim Reynolds
Tim Reynolds3mo ago
For context
No description
DiamondDragon
DiamondDragon3mo ago
My previous thread, with package.json and tsconfig settings https://discord.com/channels/1288403910284935179/1397295965169389691 @HotBBQSauce @tim7463 fyi
Ping
Ping3mo ago
hey, is anyone able to make a minimal repro? cc @tim7463 @DiamondDragon
Tim Reynolds
Tim Reynolds3mo ago
Not to hand, just tried a fresh install with pg and drizzle and it works fine. The above was with D1 via the drizzle adapter so maybe its specific to that setup I went to replicate this and the cause is the fact I've got "exactOptionalPropertyTypes": true set in my tsconfig, if you remove this option then the issue is resolved
DiamondDragon
DiamondDragon3mo ago
@Ping this isn't very minimal but should show the issue https://github.com/austinm911/zero-effect-better-t/blob/main/packages/backend/src/lib/auth.ts template is wip so lmk if you have any issues
GitHub
zero-effect-better-t/packages/backend/src/lib/auth.ts at main · au...
Contribute to austinm911/zero-effect-better-t development by creating an account on GitHub.
hegillis
hegillis3mo ago
We are seeing this as well. Happy to share tsconfig, package.json, or anything else that might be helpful.
No description
hegillis
hegillis3mo ago
Is there a github issue tracking already? I wasn't able to find one FWIW this worked for us as well to at least get rid of that error, but unclear if it's killing type inference for all the organization endpoints now
Tim Reynolds
Tim Reynolds3mo ago
Based on the example project my guess is it doesn’t support this compiler option although it was shipped in Ts 4.4 so it’s not new. I doubt it breaks anything as that option is just extended strictness about a property being defined as undefined vs not being defined at all. I assume I’ve got it on as the opennext cloudflare template must set it or it was required by arktype
hegillis
hegillis3mo ago
Yeah removing it should be ok. I still can't get type inference for the organization imports but potentially a different issue
Tim Reynolds
Tim Reynolds3mo ago
The example in the better auth repo was where I started and helped with the last issue

Did you find this page helpful?