also looking at this
fix(emit): skip a satisfies type that is cut from inside the initializer
#3123
3 files
+109
-3
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | import type { Declaration } from '../types' |
| 6 | 6 | import { formatComments } from './comments' |
| 7 | import { consumeCleanDefault, enableCleanDefaultCollection, extractSatisfiesType, inferNarrowType, isGenericType } from './type-inference' | |
| 7 | import { consumeCleanDefault, enableCleanDefaultCollection, extractSatisfiesType, inferNarrowType, isBalancedType, isGenericType } from './type-inference' | |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Format a @defaultValue tag as a standalone JSDoc block |
| @@ -109,10 +109,13 @@ export function processVariableDeclaration(decl: Declaration, keepComments: bool | ||
| 109 | 109 | let typeAnnotation = decl.typeAnnotation |
| 110 | 110 | const value = decl.value as string | undefined |
| 111 | 111 | |
| 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. | |
| 113 | 116 | if (value && value.includes(' satisfies ')) { |
| 114 | 117 | const satisfiesType = extractSatisfiesType(value) |
| 115 | if (satisfiesType) { | |
| 118 | if (satisfiesType && isBalancedType(satisfiesType)) { | |
| 116 | 119 | typeAnnotation = satisfiesType |
| 117 | 120 | } |
| 118 | 121 | } |