|
9 | 9 | hasStandardLibrarySignature, |
10 | 10 | isArrayType, |
11 | 11 | isFunctionType, |
| 12 | + isNullableType, |
12 | 13 | isNumberType, |
13 | 14 | isStandardLibraryType, |
14 | 15 | isStringType, |
@@ -115,22 +116,34 @@ export function transformBuiltinCallExpression( |
115 | 116 | } |
116 | 117 | } |
117 | 118 |
|
118 | | - if (isStringType(context, ownerType) && hasStandardLibrarySignature(context, node)) { |
| 119 | + const isStringFunction = |
| 120 | + isStringType(context, ownerType) || |
| 121 | + (expression.questionDotToken && isNullableType(context, ownerType, isStringType)); |
| 122 | + if (isStringFunction && hasStandardLibrarySignature(context, node)) { |
119 | 123 | if (isOptionalCall) return unsupportedOptionalCall(); |
120 | 124 | return transformStringPrototypeCall(context, node); |
121 | 125 | } |
122 | 126 |
|
123 | | - if (isNumberType(context, ownerType) && hasStandardLibrarySignature(context, node)) { |
| 127 | + const isNumberFunction = |
| 128 | + isNumberType(context, ownerType) || |
| 129 | + (expression.questionDotToken && isNullableType(context, ownerType, isNumberType)); |
| 130 | + if (isNumberFunction && hasStandardLibrarySignature(context, node)) { |
124 | 131 | if (isOptionalCall) return unsupportedOptionalCall(); |
125 | 132 | return transformNumberPrototypeCall(context, node); |
126 | 133 | } |
127 | 134 |
|
128 | | - if (isArrayType(context, ownerType) && hasStandardLibrarySignature(context, node)) { |
| 135 | + const isArrayFunction = |
| 136 | + isArrayType(context, ownerType) || |
| 137 | + (expression.questionDotToken && isNullableType(context, ownerType, isArrayType)); |
| 138 | + if (isArrayFunction && hasStandardLibrarySignature(context, node)) { |
129 | 139 | if (isOptionalCall) return unsupportedOptionalCall(); |
130 | 140 | return transformArrayPrototypeCall(context, node); |
131 | 141 | } |
132 | 142 |
|
133 | | - if (isFunctionType(ownerType) && hasStandardLibrarySignature(context, node)) { |
| 143 | + const isFunctionFunction = |
| 144 | + isFunctionType(ownerType) || |
| 145 | + (expression.questionDotToken && isNullableType(context, ownerType, (_, t) => isFunctionType(t))); |
| 146 | + if (isFunctionFunction && hasStandardLibrarySignature(context, node)) { |
134 | 147 | if (isOptionalCall) return unsupportedOptionalCall(); |
135 | 148 | return transformFunctionPrototypeCall(context, node); |
136 | 149 | } |
|
0 commit comments