@@ -232,12 +232,12 @@ const isNonUnionAssignableToUnion = ({
232232 if ( source . kind === 'opaque' ) {
233233 return source . isAssignableTo ( target )
234234 } else {
235- // The strategy for this case is to check whether any of the target's members are
236- // assignable to the source type. However this alone is not sufficient—for example
237- // `{ a: 'a' | 'b' }` should be assignable to `{ a: 'a' } | { a: 'b' }` even though
238- // `{ a: 'a' | 'b' }` is not directly assignable to `{ a: 'a' }` nor `{ a: 'b' }`. To
239- // make things work the target type is first converted into a standard form (e.g.
240- // `{ a: 'a' } | { a: 'b' }` is translated into `{ a: 'a' | 'b' }`.
235+ // The strategy for this case is to check whether any of the target's members are assignable to
236+ // the source type. However this alone is not sufficient—for example `{ a: 'a' | 'b' }` should
237+ // be assignable to `{ a: 'a' } | { a: 'b' }` even though `{ a: 'a' | 'b' }` is not directly
238+ // assignable to `{ a: 'a' }` nor `{ a: 'b' }`. To make things work the target type is first
239+ // converted into a standard form (e.g. `{ a: 'a' } | { a: 'b' }` is translated into
240+ // `{ a: 'a' | 'b' }`.
241241
242242 const preparedTarget = simplifyUnionType ( target )
243243
@@ -290,20 +290,18 @@ export const simplifyUnionType = (typeToSimplify: UnionType): UnionType => {
290290 const reducibleSubsets : Map <
291291 string ,
292292 {
293- readonly keys : string [ ]
293+ readonly keys : readonly string [ ]
294294 readonly typesToMerge : Set < ObjectType >
295295 }
296296 > = new Map ( )
297297 for ( const type of typeToSimplify . members ) {
298298 if ( typeof type !== 'string' && type . kind === 'object' ) {
299299 const keys = Object . keys ( type . children )
300300
301- // Object types with a single key are always mergeable with other object types
302- // containing the same single key. For example `{ a: 'a' } | { a: 'b' }` can become
303- // `{ a: 'a' | 'b' }`.
304- // TODO: Handle cases where there is more than one key but property types are
305- // compatible. For example `{ a: 'a', b: 'b' } | { a: 'b', b: 'b' }` can become
306- // `{ a: 'a' | 'b', b: 'b' }`.
301+ // Object types with a single key are always mergeable with other object types containing the
302+ // same single key. For example `{ a: 'a' } | { a: 'b' }` can become `{ a: 'a' | 'b' }`.
303+ // TODO: Handle cases where there is more than one key but property types are compatible. For
304+ // example `{ a: 'a', b: 'b' } | { a: 'b', b: 'b' }` can become `{ a: 'a' | 'b', b: 'b' }`.
307305 const fingerprint = keys [ 0 ]
308306 if ( keys . length === 1 && fingerprint !== undefined ) {
309307 const objectTypesWithThisFingerprint = reducibleSubsets . get (
@@ -319,6 +317,7 @@ export const simplifyUnionType = (typeToSimplify: UnionType): UnionType => {
319317
320318 const canonicalizedTargetMembers : Set < Atom | Exclude < Type , UnionType > > =
321319 new Set ( [ ...typeToSimplify . members ] )
320+
322321 // Reduce `reducibleSubsets` by merging all candidate, updating `canonicalizedTargetMembers`.
323322 // Merge algorithm:
324323 // - for each reducible subset of object types:
0 commit comments