@@ -199,6 +199,36 @@ function checkType({
199199 }
200200
201201 if ( type . isUnion ( ) ) {
202+ const hasStringIntersection = type . types . some ( ( t ) => {
203+ if ( t . isIntersection && t . isIntersection ( ) ) {
204+ const hasString = t . types . some ( ( it ) => it . flags & ts . TypeFlags . String ) ;
205+ const hasEmptyObject = t . types . some (
206+ ( it ) =>
207+ it . flags & ts . TypeFlags . Object &&
208+ ( ! it . symbol || ! it . symbol . members || it . symbol . members . size === 0 ) ,
209+ ) ;
210+ return hasString && hasEmptyObject ;
211+ }
212+ return false ;
213+ } ) ;
214+
215+ if ( hasStringIntersection ) {
216+ const hasLiterals = type . types . some ( ( t ) => t . flags & ts . TypeFlags . Literal ) ;
217+ if ( hasLiterals ) {
218+ const hasUndefined = type . types . some ( ( t ) => t . flags & ts . TypeFlags . Undefined ) ;
219+ if ( hasUndefined ) {
220+ return createUnionType ( {
221+ jsDoc,
222+ types : [
223+ createStringType ( { jsDoc : undefined } ) ,
224+ createUndefinedType ( { jsDoc : undefined } ) ,
225+ ] ,
226+ } ) ;
227+ }
228+ return createStringType ( { jsDoc } ) ;
229+ }
230+ }
231+
202232 const node = createUnionType ( {
203233 jsDoc,
204234 types : type . types . map ( ( x ) => checkType ( { type : x , location, typeStack, name, project } ) ) ,
@@ -207,6 +237,19 @@ function checkType({
207237 return node . types . length === 1 ? node . types [ 0 ] : node ;
208238 }
209239
240+ if ( type . isIntersection && type . isIntersection ( ) ) {
241+ const hasString = type . types . some ( ( t ) => t . flags & ts . TypeFlags . String ) ;
242+ const hasEmptyObject = type . types . some (
243+ ( t ) =>
244+ t . flags & ts . TypeFlags . Object &&
245+ ( ! t . symbol || ! t . symbol . members || t . symbol . members . size === 0 ) ,
246+ ) ;
247+
248+ if ( hasString && hasEmptyObject ) {
249+ return createStringType ( { jsDoc } ) ;
250+ }
251+ }
252+
210253 if ( type . flags & ts . TypeFlags . TypeParameter ) {
211254 const baseConstraintOfType = project . checker . getBaseConstraintOfType ( type ) ;
212255
0 commit comments