ReviewOS

also looking at this

stacks/dtsx

fix(emit): skip a satisfies type that is cut from inside the initializer

#3123
Open mkantautas wants to merge fix/satisfies-top-level into main
3 files +109 -3
packages/dtsx/src/processor/declarations.tsmodified+6-3
Changes to packages/dtsx/src/processor/declarations.ts
@@ -4,7 +4,7 @@
44
55import type { Declaration } from '../types'
66import { formatComments } from './comments'
7import { consumeCleanDefault, enableCleanDefaultCollection, extractSatisfiesType, inferNarrowType, isGenericType } from './type-inference'
7import { consumeCleanDefault, enableCleanDefaultCollection, extractSatisfiesType, inferNarrowType, isBalancedType, isGenericType } from './type-inference'
88
99/**
1010 * Format a @defaultValue tag as a standalone JSDoc block
@@ -109,10 +109,13 @@ export function processVariableDeclaration(decl: Declaration, keepComments: bool
109109 let typeAnnotation = decl.typeAnnotation
110110 const value = decl.value as string | undefined
111111
112 // Check for 'satisfies' operator - extract the type from the satisfies clause
112 // Check for 'satisfies' operator - extract the type from the satisfies clause.
113 // The last ` satisfies ` can sit in a comment, a string or a nested element
114 // (`[{ id: 1 } satisfies Item, y]`); the text after it then closes a bracket
115 // or leaves a string open, and is not a type to declare.
113116 if (value && value.includes(' satisfies ')) {
114117 const satisfiesType = extractSatisfiesType(value)
115 if (satisfiesType) {
118 if (satisfiesType && isBalancedType(satisfiesType)) {
116119 typeAnnotation = satisfiesType
117120 }
118121 }