Skip to content

Commit 70bbca7

Browse files
authored
fix(types): Typescript v5 cannot infer types correctly (#2314)
1 parent 8e5cf6e commit 70bbca7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.changeset/tame-olives-check.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/types/src/organizationMembership.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ interface Base {
88
role: string;
99
}
1010

11+
interface Placeholder {
12+
permission: unknown;
13+
role: unknown;
14+
}
15+
1116
declare global {
1217
interface ClerkAuthorization {}
1318
}
@@ -45,14 +50,16 @@ export interface OrganizationMembershipResource extends ClerkResource {
4550
update: (updateParams: UpdateOrganizationMembershipParams) => Promise<OrganizationMembershipResource>;
4651
}
4752

48-
export type OrganizationCustomPermissionKey = 'permission' extends keyof ClerkAuthorization
49-
? // @ts-ignore Typescript cannot infer the existence of the `permission` key even if we checking it above
50-
ClerkAuthorization['permission']
53+
export type OrganizationCustomPermissionKey = ClerkAuthorization extends Placeholder
54+
? ClerkAuthorization['permission'] extends string
55+
? ClerkAuthorization['permission']
56+
: Base['permission']
5157
: Base['permission'];
5258

53-
export type OrganizationCustomRoleKey = 'role' extends keyof ClerkAuthorization
54-
? // @ts-ignore Typescript cannot infer the existence of the `role` key even if we checking it above
55-
ClerkAuthorization['role']
59+
export type OrganizationCustomRoleKey = ClerkAuthorization extends Placeholder
60+
? ClerkAuthorization['role'] extends string
61+
? ClerkAuthorization['role']
62+
: Base['role']
5663
: Base['role'];
5764

5865
/**

0 commit comments

Comments
 (0)