File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { LazyGetter as Once } from 'lazy-get-decorator';
4
4
import { DateTime } from 'luxon' ;
5
5
import { keys as keysOf } from 'ts-transformer-keys' ;
6
6
import { inspect } from 'util' ;
7
+ import type { ResourceMap } from '~/core' ;
7
8
import { $ , abstractType , e } from '~/core/edgedb/reexports' ;
8
9
import { ScopedRole } from '../components/authorization' ;
9
10
import { CalculatedSymbol } from './calculated.decorator' ;
@@ -128,8 +129,8 @@ export class EnhancedResource<T extends ResourceShape<any>> {
128
129
: undefined ;
129
130
}
130
131
131
- get name ( ) {
132
- return this . type . name ;
132
+ get name ( ) : ResourceName < T > {
133
+ return this . type . name as any ;
133
134
}
134
135
135
136
/**
@@ -282,6 +283,15 @@ export const isResourceClass = <T>(
282
283
) : cls is ResourceShape < T > =>
283
284
'Props' in cls && Array . isArray ( cls . Props ) && cls . Props . length > 0 ;
284
285
286
+ export type ResourceName < TResourceStatic extends ResourceShape < any > > = {
287
+ [ Name in keyof ResourceMap ] : ResourceMap [ Name ] extends TResourceStatic // Only self or subclasses
288
+ ? TResourceStatic extends ResourceMap [ Name ] // Exclude subclasses
289
+ ? Name
290
+ : never
291
+ : never ;
292
+ } [ keyof ResourceMap ] &
293
+ string ;
294
+
285
295
export type MaybeUnsecuredInstance < TResourceStatic extends ResourceShape < any > > =
286
296
MaybeSecured < InstanceType < TResourceStatic > > ;
287
297
You can’t perform that action at this time.
0 commit comments