File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 11import AwaitEventEmitter from 'await-event-emitter' ;
2+ import { partition } from 'lodash' ;
23import { PropertyDeclarationStructure } from 'ts-morph' ;
34
45import { DMMF } from '../types' ;
@@ -17,11 +18,12 @@ function classProperty(
1718) {
1819 const { location, isList, propertyType } = eventArguments ;
1920 if ( [ 'inputObjectTypes' , 'outputObjectTypes' ] . includes ( location ) && ! isList ) {
20- const types = propertyType . filter ( t => t !== 'null' ) ;
21- property . type = types . map ( t => `InstanceType<typeof ${ t } >` ) . join ( ' | ' ) ;
22- if ( types . length !== propertyType . length ) {
23- // If null was removed
24- property . type += ' | null' ;
25- }
21+ const [ safeTypes , instanceofTypes ] = partition (
22+ propertyType ,
23+ t => t === 'null' || t . startsWith ( 'Prisma.' ) ,
24+ ) ;
25+ const mappedInstanceofTypes = instanceofTypes . map ( t => `InstanceType<typeof ${ t } >` ) ;
26+
27+ property . type = [ ...mappedInstanceofTypes , ...safeTypes ] . join ( ' | ' ) ;
2628 }
2729}
Original file line number Diff line number Diff line change @@ -1531,6 +1531,25 @@ describe('emit single', () => {
15311531 } ) ) ;
15321532 expect ( types ) . toHaveLength ( 0 ) ;
15331533 } ) ;
1534+
1535+ it ( 'type started with Prisma should not be wrapped to instanceof' , async ( ) => {
1536+ const types = sourceFile
1537+ . getClasses ( )
1538+ . flatMap ( c => c . getProperties ( ) . map ( p => ( { c, p } ) ) )
1539+ . map ( ( { c, p } ) => ( {
1540+ c,
1541+ p,
1542+ propertyType : p . getStructure ( ) . type ,
1543+ } ) )
1544+ . map ( ( { propertyType } ) => String ( propertyType ) )
1545+ . filter (
1546+ propertyType =>
1547+ propertyType . includes ( 'Prisma.' ) &&
1548+ propertyType . startsWith ( 'InstanceType<' ) ,
1549+ ) ;
1550+
1551+ expect ( types ) . toHaveLength ( 0 ) ;
1552+ } ) ;
15341553 } ) ;
15351554
15361555 describe ( 'emit single second gen' , ( ) => {
You can’t perform that action at this time.
0 commit comments