tsc-ts 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (584) hide show
  1. package/README.md +33 -1
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2350 -0
  5. package/dist/api/compiler/ast.js +11206 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1240 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2358 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1640 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +356 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +787 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +315 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +290 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +579 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2573 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +900 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +441 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +198 -0
  69. package/dist/api/compiler/checker-members.js +2126 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +479 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +270 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +788 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
  93. package/dist/api/compiler/checker-symbol-types.js +1885 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1782 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2501 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1027 -0
  103. package/dist/api/compiler/checker-types.js +1697 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +491 -0
  109. package/dist/api/compiler/checker.js +912 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +167 -0
  119. package/dist/api/compiler/diagnostics.js +820 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +117 -0
  123. package/dist/api/compiler/file-include.js +536 -0
  124. package/dist/api/compiler/file-loader.d.ts +261 -0
  125. package/dist/api/compiler/file-loader.js +1257 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +799 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +36 -0
  135. package/dist/api/compiler/link-tables.js +83 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +744 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +219 -0
  191. package/dist/api/compiler/parallel-parse.js +537 -0
  192. package/dist/api/compiler/parser.d.ts +587 -0
  193. package/dist/api/compiler/parser.js +6407 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +154 -0
  203. package/dist/api/compiler/printer/emit-context.js +576 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +526 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1011 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +894 -0
  244. package/dist/api/compiler/symbol.d.ts +240 -0
  245. package/dist/api/compiler/symbol.js +228 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +676 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2380 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +203 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +254 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12862 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2703 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1194 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +359 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3584 -0
  407. package/src/compiler/checker-heritage.ts +1233 -0
  408. package/src/compiler/checker-inference.ts +2576 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1924 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2436 -0
  415. package/src/compiler/checker-modules.ts +2886 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +575 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +2107 -0
  427. package/src/compiler/checker-symbols.ts +2150 -0
  428. package/src/compiler/checker-type-factory.ts +2579 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2502 -0
  431. package/src/compiler/checker-types.ts +2340 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1116 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +897 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +673 -0
  444. package/src/compiler/file-loader.ts +1528 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2784 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +894 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +98 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1069 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3425 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1951 -0
  481. package/src/compiler/parallel-parse.ts +590 -0
  482. package/src/compiler/parse-thread.ts +140 -0
  483. package/src/compiler/parser.ts +7716 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +679 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +592 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1419 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1071 -0
  510. package/src/compiler/symbol.ts +439 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +245 -0
  552. package/src/compiler/transformers/syntax-facts.ts +353 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1418 -0
  562. package/src/compiler/tsc-cli.ts +666 -0
  563. package/src/compiler/tsc-compile.ts +437 -0
  564. package/src/compiler/tsc-watch.ts +854 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,1885 @@
1
+ // Types of value symbols: variables, parameters, properties, accessors, functions, classes,
2
+ // enums, modules and aliases; optionality and widening.
3
+ import { checkJsxAttribute } from './checker-jsx.js';
4
+ import { getTargetOfAliasDeclaration, resolveExternalModuleSymbol } from './checker-modules.js';
5
+ import { cachedTypeKey } from './checker-types.js';
6
+ import { NodeVisitor, getArguments, getInitializer, getName, getParameters, getType, getBody, getSymbol, getMembers, getDotDotDotToken, getElements, getExpression, getLocals, getPostfixToken, getQuestionToken, getText, } from './ast.js';
7
+ import { declarationNameToString, findConstructorDeclaration, getCombinedModifierFlags, getCombinedNodeFlags, getNameOfDeclaration, getRootDeclaration, getSourceFileOfNode, hasStaticModifier, hasSyntacticModifier, isCatchClauseVariableDeclarationOrBindingElement, isExternalModule, isJsonSourceFile, isTypeNodeKind, skipParentheses, } from './binder-utilities.js';
8
+ import { identifierToKeywordKind } from './scanner.js';
9
+ import { tsgoCheckerSlots } from './symbol-accessibility.js';
10
+ import { getSymbolId } from './symbol.js';
11
+ import { createDiagnosticForNode } from './checker.js';
12
+ import { IndexInfo, } from './checker-types.js';
13
+ import { createAnonymousType, createTypeReference, getIntersectionType, getUnionType, getUnionTypeEx, getWidenedLiteralType, isArrayOrTupleType, isEmptyObjectType, newObjectType, removeType, filterType, typesOf, getTypeArguments, } from './checker-type-factory.js';
14
+ import { getDeclarationOfAliasSymbol, getParentOfSymbol, getSymbolFlags, getSymbolOfDeclaration, popTypeResolution, pushTypeResolution, reportCircularityError, resolveAlias, getMergedSymbol, getGlobalTypeAliasSymbol, resolveName, getGlobalSymbol, } from './checker-symbols.js';
15
+ import { getBaseConstructorTypeOfClass, getDeclaredTypeOfClassOrInterface, getDeclaredTypeOfEnumMember, getDeclaredTypeOfSymbol, } from './checker-declared-types.js';
16
+ import { getESSymbolLikeTypeForNode, getTypeFromTypeNode, getTypeAliasInstantiation } from './checker-type-nodes.js';
17
+ import { getFlowTypeInConstructor, getFlowTypeInStaticBlocks, getTypeOfPropertyInBaseClass, } from './checker-classes.js';
18
+ import { instantiateType } from './instantiation.js';
19
+ import { getIndexInfosOfType, getPropertiesOfObjectType, getPropertiesOfType, getPropertyOfObjectType, isObjectLiteralType, } from './checker-members.js';
20
+ import { typeToString, symbolToString } from './type-printer.js';
21
+ import { getTypeOfMappedSymbol, getIndexType } from './checker-type-operators.js';
22
+ import { getReturnTypeOfSignature, getSignatureFromDeclaration, getTypeOfParameter as getTypeOfParameterOfSignature, } from './checker-signatures.js';
23
+ import { getReturnTypeFromBody, getTypeOfObjectLiteralMethod, ReturnCollector, shouldReportErrorsFromWideningWithContextualSignature, } from './checker-functions.js';
24
+ import { getTypeOfReverseMappedSymbol } from './checker-inference.js';
25
+ import { checkDeclarationInitializer, getContextuallyTypedParameterType, getContextualThisParameterType, checkExpressionCached, checkExpressionEx, isConstTypeReference, } from './checker-expressions.js';
26
+ import { checkPropertyAssignment, checkShorthandPropertyAssignment } from './checker-object-literals.js';
27
+ import { getTypeForBindingElement, getTypeFromBindingPattern } from './checker-destructuring.js';
28
+ import { checkRightHandSideOfForOf } from './checker-statements.js';
29
+ import { getTypeWithFacts, hasTypeFacts, getNonNullableType } from './checker-flow.js';
30
+ import { getTypeOfModuleExportsSymbol, getWidenedTypeForAssignmentDeclaration } from './checker-javascript.js';
31
+ export function getTypeOfSymbol(c, symbol) {
32
+ const checkFlags = symbol.checkFlags;
33
+ if ((checkFlags & 65536 /* CheckFlags.DeferredType */) !== 0)
34
+ return getTypeOfSymbolWithDeferredType(c, symbol);
35
+ if ((checkFlags & 1 /* CheckFlags.Instantiated */) !== 0)
36
+ return getTypeOfInstantiatedSymbol(c, symbol);
37
+ if ((checkFlags & 262144 /* CheckFlags.Mapped */) !== 0)
38
+ return getTypeOfMappedSymbol(c, symbol);
39
+ if ((checkFlags & 8192 /* CheckFlags.ReverseMapped */) !== 0)
40
+ return getTypeOfReverseMappedSymbol(c, symbol);
41
+ const flags = symbol.flags;
42
+ if ((flags & 98304 /* SymbolFlags.Accessor */) !== 0)
43
+ return getTypeOfAccessors(c, symbol);
44
+ if ((flags & (3 /* SymbolFlags.Variable */ | 4 /* SymbolFlags.Property */)) !== 0)
45
+ return getTypeOfVariableOrParameterOrProperty(c, symbol);
46
+ if ((flags &
47
+ (16 /* SymbolFlags.Function */ | 8192 /* SymbolFlags.Method */ | 32 /* SymbolFlags.Class */ | 384 /* SymbolFlags.Enum */ | 512 /* SymbolFlags.ValueModule */)) !==
48
+ 0)
49
+ return getTypeOfFuncClassEnumModule(c, symbol);
50
+ if ((flags & 8 /* SymbolFlags.EnumMember */) !== 0)
51
+ return getTypeOfEnumMember(c, symbol);
52
+ if ((flags & 2097152 /* SymbolFlags.Alias */) !== 0)
53
+ return getTypeOfAlias(c, symbol);
54
+ return c.errorType;
55
+ }
56
+ export function getTypeOfParameter(c, symbol) {
57
+ return getTypeOfParameterOfSignature(c, symbol);
58
+ }
59
+ export function getNonMissingTypeOfSymbol(c, symbol) {
60
+ return removeMissingType(c, getTypeOfSymbol(c, symbol), (symbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0);
61
+ }
62
+ function getTypeOfSymbolWithDeferredType(c, symbol) {
63
+ const links = c.symbolLinks(symbol);
64
+ const id = symbol.id;
65
+ if (c.symbolTypes.get(id) === undefined) {
66
+ const constituents = links.deferralConstituents;
67
+ c.symbolTypes.set(id, (links.deferralParent.flags & 134217728 /* TypeFlags.Union */) !== 0
68
+ ? getUnionType(c, constituents)
69
+ : getIntersectionType(c, constituents));
70
+ }
71
+ return c.symbolTypes.get(id);
72
+ }
73
+ function getWriteTypeOfSymbolWithDeferredType(c, symbol) {
74
+ const links = c.symbolLinks(symbol);
75
+ if (links.writeType === undefined) {
76
+ const constituents = links.deferralWriteConstituents;
77
+ if (constituents === undefined)
78
+ links.writeType = getTypeOfSymbolWithDeferredType(c, symbol);
79
+ else
80
+ links.writeType =
81
+ (links.deferralParent.flags & 134217728 /* TypeFlags.Union */) !== 0
82
+ ? getUnionType(c, constituents)
83
+ : getIntersectionType(c, constituents);
84
+ }
85
+ return links.writeType;
86
+ }
87
+ function getTypeOfInstantiatedSymbol(c, symbol) {
88
+ const id = getSymbolId(symbol);
89
+ let type = c.symbolTypes.get(id);
90
+ if (type === undefined) {
91
+ type = instantiateType(c, getTypeOfSymbol(c, c.symbolTargets.get(id)), c.symbolMappers.get(id));
92
+ c.symbolTypes.set(id, type);
93
+ }
94
+ return type;
95
+ }
96
+ export function getWriteTypeOfSymbol(c, symbol) {
97
+ if ((symbol.checkFlags & 2 /* CheckFlags.SyntheticProperty */) !== 0) {
98
+ if ((symbol.checkFlags & 65536 /* CheckFlags.DeferredType */) !== 0)
99
+ return getWriteTypeOfSymbolWithDeferredType(c, symbol);
100
+ const id = getSymbolId(symbol);
101
+ return c.symbolLinkTable.get(id)?.writeType ?? c.symbolTypes.get(id) ?? getTypeOfSymbol(c, symbol);
102
+ }
103
+ if ((symbol.flags & 4 /* SymbolFlags.Property */) !== 0)
104
+ return removeMissingType(c, getTypeOfSymbol(c, symbol), (symbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0);
105
+ if ((symbol.flags & 98304 /* SymbolFlags.Accessor */) !== 0) {
106
+ if ((symbol.checkFlags & 1 /* CheckFlags.Instantiated */) !== 0) {
107
+ const links = c.symbolLinks(symbol);
108
+ const symbolId = symbol.id;
109
+ if (links.writeType === undefined)
110
+ links.writeType = instantiateType(c, getWriteTypeOfSymbol(c, c.symbolTargets.get(symbolId)), c.symbolMappers.get(symbolId));
111
+ return links.writeType;
112
+ }
113
+ return getWriteTypeOfAccessors(c, symbol);
114
+ }
115
+ return getTypeOfSymbol(c, symbol);
116
+ }
117
+ // ---- Variables, parameters and properties
118
+ function getTypeOfVariableOrParameterOrProperty(c, symbol) {
119
+ const id = getSymbolId(symbol);
120
+ const cached = c.symbolTypes.get(id);
121
+ if (cached !== undefined)
122
+ return cached;
123
+ const t = getTypeOfVariableOrParameterOrPropertyWorker(c, symbol);
124
+ // Contextually typed parameters may get their type later; don't cache theirs.
125
+ if (c.symbolTypes.get(id) === undefined && !isParameterOfContextSensitiveSignature(c, symbol))
126
+ c.symbolTypes.set(id, t);
127
+ return t;
128
+ }
129
+ function isParameterOfContextSensitiveSignature(c, symbol) {
130
+ let decl = symbol.valueDeclaration;
131
+ if (decl === undefined)
132
+ return false;
133
+ if (decl.kind === 209 /* SyntaxKind.BindingElement */)
134
+ decl = getRootDeclaration(decl);
135
+ return decl.kind === 170 /* SyntaxKind.Parameter */ && isContextSensitiveFunctionLikeLazy(c, decl.parent);
136
+ }
137
+ import { isContextSensitiveFunctionOrObjectLiteralMethod as isContextSensitiveFunctionLikeLazy } from './checker-expressions.js';
138
+ function getTypeOfVariableOrParameterOrPropertyWorker(c, symbol) {
139
+ if ((symbol.flags & 4194304 /* SymbolFlags.Prototype */) !== 0)
140
+ return getTypeOfPrototypeProperty(c, symbol);
141
+ if (symbol === c.requireSymbol)
142
+ return c.anyType;
143
+ const declaration = symbol.valueDeclaration;
144
+ if (declaration === undefined)
145
+ return c.errorType;
146
+ // The `export=` symbol of a JSON file has the type of its value.
147
+ if (declaration.kind === 307 /* SyntaxKind.SourceFile */ && isJsonSourceFile(declaration)) {
148
+ const statements = declaration.statements.nodes;
149
+ if (statements.length === 0)
150
+ return c.emptyObjectType;
151
+ return getWidenedType(c, getWidenedLiteralType(c, checkExpression(c, getExpression(statements[0]))));
152
+ }
153
+ if (!pushTypeResolution(c, symbol, 0 /* TypeSystemPropertyName.Type */))
154
+ return reportCircularityError(c, symbol);
155
+ // Like tsgo, the type resolution stays pushed: until popped by an enclosing resolution, its cached
156
+ // type ends cycle detection there, so aliases like `module.exports.b = module.exports.a` resolve.
157
+ if ((symbol.flags & 134217728 /* SymbolFlags.ModuleExports */) !== 0)
158
+ return getTypeOfModuleExportsSymbol(c, symbol);
159
+ let result;
160
+ switch (declaration.kind) {
161
+ case 170 /* SyntaxKind.Parameter */:
162
+ case 173 /* SyntaxKind.PropertyDeclaration */:
163
+ case 172 /* SyntaxKind.PropertySignature */:
164
+ case 261 /* SyntaxKind.VariableDeclaration */:
165
+ case 209 /* SyntaxKind.BindingElement */:
166
+ result = getWidenedTypeForVariableLikeDeclaration(c, declaration, true);
167
+ break;
168
+ case 303 /* SyntaxKind.PropertyAssignment */:
169
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
170
+ case 175 /* SyntaxKind.MethodDeclaration */:
171
+ // The declared symbol of an object literal member, as opposed to the checked literal's property.
172
+ if (declaration.kind === 303 /* SyntaxKind.PropertyAssignment */)
173
+ result = checkPropertyAssignment(c, declaration, 0 /* CheckMode.Normal */);
174
+ else if (declaration.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */)
175
+ result = checkShorthandPropertyAssignment(c, declaration, true, 0 /* CheckMode.Normal */);
176
+ else
177
+ result = getTypeOfObjectLiteralMethod(c, declaration, 0 /* CheckMode.Normal */);
178
+ break;
179
+ case 292 /* SyntaxKind.JsxAttribute */:
180
+ result = checkJsxAttribute(c, declaration, 0 /* CheckMode.Normal */);
181
+ break;
182
+ case 278 /* SyntaxKind.ExportAssignment */: {
183
+ const typeNode = getType(declaration);
184
+ result =
185
+ typeNode !== undefined
186
+ ? getTypeFromTypeNode(c, typeNode)
187
+ : widenTypeForVariableLikeDeclaration(c, checkExpressionCached(c, getExpression(declaration)), declaration, false);
188
+ break;
189
+ }
190
+ case 306 /* SyntaxKind.EnumMember */:
191
+ result = getTypeOfEnumMember(c, symbol);
192
+ break;
193
+ case 227 /* SyntaxKind.BinaryExpression */:
194
+ case 214 /* SyntaxKind.CallExpression */:
195
+ result = getWidenedTypeForAssignmentDeclaration(c, symbol);
196
+ break;
197
+ default:
198
+ result = c.anyType;
199
+ }
200
+ if (!popTypeResolution(c))
201
+ return reportCircularityError(c, symbol);
202
+ return result;
203
+ }
204
+ export function getWidenedTypeForVariableLikeDeclaration(c, declaration, reportErrors) {
205
+ return widenTypeForVariableLikeDeclaration(c, getTypeForVariableLikeDeclaration(c, declaration, true), declaration, reportErrors);
206
+ }
207
+ /** Whether a parameter, property or method is declared with `?`. */
208
+ export function isOptionalDeclaration(node) {
209
+ if (getQuestionToken(node) !== undefined)
210
+ return true;
211
+ // Properties and methods mark optionality with a `?` postfix token.
212
+ const postfix = getPostfixToken(node);
213
+ return postfix !== undefined && postfix.kind === 57 /* SyntaxKind.QuestionToken */;
214
+ }
215
+ function isEmptyArrayLiteral(node) {
216
+ return node.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ && getElements(node).nodes.length === 0;
217
+ }
218
+ function isNullOrUndefined(node) {
219
+ let n = node;
220
+ while (n.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
221
+ n = getExpression(n);
222
+ return n.kind === 105 /* SyntaxKind.NullKeyword */ || (n.kind === 79 /* SyntaxKind.Identifier */ && getText(n) === 'undefined');
223
+ }
224
+ function isBindingPattern(node) {
225
+ return (node !== undefined &&
226
+ (node.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || node.kind === 208 /* SyntaxKind.ArrayBindingPattern */));
227
+ }
228
+ /** The declared or inferred type of a variable-like declaration; undefined when nothing can be inferred. */
229
+ export function getTypeForVariableLikeDeclaration(c, declaration, includeOptionality, checkMode = 0 /* CheckMode.Normal */) {
230
+ if (declaration.kind === 261 /* SyntaxKind.VariableDeclaration */) {
231
+ const grandParent = declaration.parent.parent;
232
+ if (grandParent.kind === 250 /* SyntaxKind.ForInStatement */) {
233
+ // `for (k in x)` declares k as string, or keyof T for generic x.
234
+ let objectType = checkExpressionEx(c, getExpression(grandParent), checkMode);
235
+ if (hasTypeFacts(c, objectType, 50331648 /* TypeFacts.IsUndefinedOrNull */))
236
+ objectType = getNonNullableType(c, objectType);
237
+ const indexType = getIndexType(c, objectType);
238
+ return (indexType.flags & (524288 /* TypeFlags.TypeParameter */ | 2097152 /* TypeFlags.Index */)) !== 0
239
+ ? getExtractStringType(c, indexType)
240
+ : c.stringType;
241
+ }
242
+ if (grandParent.kind === 251 /* SyntaxKind.ForOfStatement */)
243
+ return checkRightHandSideOfForOf(c, grandParent);
244
+ }
245
+ else if (declaration.kind === 209 /* SyntaxKind.BindingElement */)
246
+ return getTypeForBindingElement(c, declaration);
247
+ const isProperty = (declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */ &&
248
+ (getCombinedModifierFlags(declaration) & 512 /* ModifierFlags.Accessor */) === 0) ||
249
+ declaration.kind === 172 /* SyntaxKind.PropertySignature */;
250
+ const isOptional = includeOptionality && isOptionalDeclaration(declaration);
251
+ const typeNode = getType(declaration);
252
+ const declaredType = typeNode !== undefined ? getTypeFromTypeNode(c, typeNode) : undefined;
253
+ if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
254
+ if (declaredType !== undefined)
255
+ return (declaredType.flags & 3 /* TypeFlags.AnyOrUnknown */) !== 0 ? declaredType : c.errorType;
256
+ return c.useUnknownInCatchVariables ? c.unknownType : c.anyType;
257
+ }
258
+ if (declaredType !== undefined)
259
+ return addOptionality(c, declaredType, isProperty, isOptional);
260
+ if (c.noImplicitAny &&
261
+ declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
262
+ !isBindingPattern(getName(declaration)) &&
263
+ (getCombinedModifierFlags(declaration) & 32 /* ModifierFlags.Export */) === 0 &&
264
+ (declaration.flags & 8388608 /* NodeFlags.Ambient */) === 0) {
265
+ // Control-flow typed `any` for uninitialized or null/undefined-initialized let and var.
266
+ const initializer = getInitializer(declaration);
267
+ if ((getCombinedNodeFlags(declaration) & 6 /* NodeFlags.Constant */) === 0 &&
268
+ (initializer === undefined || isNullOrUndefined(initializer)))
269
+ return c.autoType;
270
+ if (initializer !== undefined && isEmptyArrayLiteral(initializer))
271
+ return c.autoArrayType;
272
+ }
273
+ if (declaration.kind === 170 /* SyntaxKind.Parameter */) {
274
+ if (getSymbol(declaration) === undefined)
275
+ return undefined;
276
+ const fn = declaration.parent;
277
+ // A set accessor parameter takes the getter's type.
278
+ if (fn.kind === 179 /* SyntaxKind.SetAccessor */) {
279
+ const fnSymbol = getSymbolOfDeclaration(c, fn);
280
+ const getter = fnSymbol?.declarations.find((d) => d.kind === 178 /* SyntaxKind.GetAccessor */);
281
+ if (getter !== undefined) {
282
+ const getterSignature = getSignatureFromDeclaration(c, getter);
283
+ // An unannotated `this` of a setter takes the getter's `this` type.
284
+ const params = getParameters(fn).nodes;
285
+ if (params.length === 2 && params[0] === declaration && getSymbol(declaration).name === 'this')
286
+ return getterSignature.thisParameter !== undefined
287
+ ? getTypeOfSymbol(c, getterSignature.thisParameter)
288
+ : c.anyType;
289
+ return getReturnTypeOfSignature(c, getterSignature);
290
+ }
291
+ }
292
+ const fullSignatureType = getParameterTypeOfFullSignature(c, fn, declaration);
293
+ if (fullSignatureType !== undefined)
294
+ return fullSignatureType;
295
+ const t = getSymbol(declaration).name === 'this'
296
+ ? getContextualThisParameterType(c, fn)
297
+ : getContextuallyTypedParameterType(c, declaration);
298
+ if (t !== undefined)
299
+ return addOptionality(c, t, false, isOptional);
300
+ }
301
+ const initializer = getInitializer(declaration);
302
+ if (initializer !== undefined) {
303
+ const t = widenTypeInferredFromInitializer(c, declaration, checkDeclarationInitializer(c, declaration, checkMode));
304
+ return addOptionality(c, t, isProperty, isOptional);
305
+ }
306
+ if (c.noImplicitAny && declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */) {
307
+ // Without an annotation or initializer, the type comes from `this` assignments in the
308
+ // constructor or static blocks.
309
+ const symbol = getSymbol(declaration);
310
+ const isAmbient = hasSyntacticModifier(declaration, 128 /* ModifierFlags.Ambient */);
311
+ let t;
312
+ if (!hasStaticModifier(declaration)) {
313
+ const constructor = findConstructorDeclaration(declaration.parent);
314
+ if (constructor !== undefined)
315
+ t = getFlowTypeInConstructor(c, symbol, constructor);
316
+ else if (isAmbient)
317
+ t = getTypeOfPropertyInBaseClass(c, symbol);
318
+ }
319
+ else {
320
+ const staticBlocks = [];
321
+ for (const member of getMembers(declaration.parent).nodes)
322
+ if (member.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
323
+ staticBlocks.push(member);
324
+ if (staticBlocks.length !== 0)
325
+ t = getFlowTypeInStaticBlocks(c, symbol, staticBlocks);
326
+ else if (isAmbient)
327
+ t = getTypeOfPropertyInBaseClass(c, symbol);
328
+ }
329
+ return t !== undefined ? addOptionality(c, t, true, isOptional) : undefined;
330
+ }
331
+ if (declaration.kind === 292 /* SyntaxKind.JsxAttribute */)
332
+ return c.trueType;
333
+ if (isBindingPattern(getName(declaration)))
334
+ return getTypeFromBindingPattern(c, getName(declaration), false, true);
335
+ return undefined;
336
+ }
337
+ export function widenTypeInferredFromInitializer(c, declaration, t) {
338
+ const widened = getWidenedLiteralTypeForInitializer(c, declaration, t);
339
+ // `null`, `undefined` and `[]` initializers in JavaScript are implicitly `any` and `any[]`.
340
+ if (isInJSFile(declaration)) {
341
+ if (widened === (c.strictNullChecks ? c.implicitNeverType : c.undefinedWideningType)) {
342
+ reportImplicitAny(c, declaration, c.anyType);
343
+ return c.anyType;
344
+ }
345
+ if (isEmptyArrayLiteralType(c, widened)) {
346
+ reportImplicitAny(c, declaration, c.anyArrayType);
347
+ return c.anyArrayType;
348
+ }
349
+ }
350
+ return widened;
351
+ }
352
+ export function getWidenedLiteralTypeForInitializer(c, declaration, t) {
353
+ if ((getCombinedNodeFlags(declaration) & 6 /* NodeFlags.Constant */) !== 0 || isDeclarationReadonly(declaration))
354
+ return t;
355
+ return getWidenedLiteralType(c, t);
356
+ }
357
+ function isDeclarationReadonly(declaration) {
358
+ return ((getCombinedModifierFlags(declaration) & 8 /* ModifierFlags.Readonly */) !== 0 && declaration.kind !== 170 /* SyntaxKind.Parameter */);
359
+ }
360
+ function isGlobalSymbolConstructor(c, node) {
361
+ const symbol = getSymbolOfDeclaration(c, node);
362
+ return symbol !== undefined && symbol === getGlobalSymbol(c, 'SymbolConstructor', 788968 /* SymbolFlags.Type */, undefined);
363
+ }
364
+ export function widenTypeForVariableLikeDeclaration(c, t, declaration, reportErrors) {
365
+ if (t !== undefined) {
366
+ // `symbol` properties merged into the global SymbolConstructor are unique symbols, as libraries
367
+ // that predate `unique symbol` declare them.
368
+ if ((t.flags & 512 /* TypeFlags.ESSymbol */) !== 0 && isGlobalSymbolConstructor(c, declaration.parent))
369
+ t = getESSymbolLikeTypeForNode(c, declaration);
370
+ if (reportErrors)
371
+ reportErrorsFromWidening(c, declaration, t, 0 /* WideningKind.Normal */);
372
+ // A unique symbol type from another declaration widens.
373
+ if ((t.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0 &&
374
+ (declaration.kind === 209 /* SyntaxKind.BindingElement */ || getType(declaration) === undefined) &&
375
+ t.symbol !== getSymbolOfDeclaration(c, declaration))
376
+ t = c.esSymbolType;
377
+ return getWidenedType(c, t);
378
+ }
379
+ // Rest parameters default to any[], others to any.
380
+ const isRest = declaration.kind === 170 /* SyntaxKind.Parameter */ && getDotDotDotToken(declaration) !== undefined;
381
+ const result = isRest ? c.anyArrayType : c.anyType;
382
+ if (reportErrors && !declarationBelongsToPrivateAmbientMember(declaration))
383
+ reportImplicitAny(c, declaration, result);
384
+ return result;
385
+ }
386
+ export function declarationBelongsToPrivateAmbientMember(declaration) {
387
+ const root = getRootDeclaration(declaration);
388
+ const member = root.kind === 170 /* SyntaxKind.Parameter */ ? root.parent : root;
389
+ return isPrivateWithinAmbient(member);
390
+ }
391
+ export function isPrivateWithinAmbient(node) {
392
+ return (((getCombinedModifierFlags(node) & 2 /* ModifierFlags.Private */) !== 0 || isPrivateIdentifierClassElement(node)) &&
393
+ (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0);
394
+ }
395
+ function isPrivateIdentifierClassElement(node) {
396
+ const name = getName(node);
397
+ return name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */;
398
+ }
399
+ /**
400
+ * Implicit-any widening of null/undefined, which strictNullChecks avoids. A function's inferred
401
+ * types report it only without a contextual signature, or when the contextual type is generic.
402
+ */
403
+ export function reportErrorsFromWidening(c, declaration, t, wideningKind) {
404
+ if (!c.noImplicitAny || (t.objectFlags & 65536 /* ObjectFlags.ContainsWideningType */) === 0)
405
+ return;
406
+ if (wideningKind !== 0 /* WideningKind.Normal */ &&
407
+ !(isFunctionLikeDeclarationKind(declaration.kind) &&
408
+ shouldReportErrorsFromWideningWithContextualSignature(c, declaration, wideningKind)))
409
+ return;
410
+ // Implicit any errors are reported within the type where possible, else on the declaration.
411
+ if (!reportWideningErrorsInType(c, t))
412
+ reportImplicitAny(c, declaration, t, wideningKind);
413
+ }
414
+ function reportWideningErrorsInType(c, t) {
415
+ let errorReported = false;
416
+ if ((t.objectFlags & 65536 /* ObjectFlags.ContainsWideningType */) === 0)
417
+ return false;
418
+ if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0) {
419
+ if (someEmptyObjectType(c, typesOf(t)))
420
+ errorReported = true;
421
+ else
422
+ for (const s of typesOf(t))
423
+ errorReported = errorReported || reportWideningErrorsInType(c, s);
424
+ }
425
+ else if (isArrayOrTupleType(c, t)) {
426
+ for (const s of getTypeArguments(c, t))
427
+ errorReported = errorReported || reportWideningErrorsInType(c, s);
428
+ }
429
+ else if (isObjectLiteralType(t)) {
430
+ for (const p of getPropertiesOfObjectType(c, t)) {
431
+ const s = getTypeOfSymbol(c, p);
432
+ if ((s.objectFlags & 65536 /* ObjectFlags.ContainsWideningType */) === 0)
433
+ continue;
434
+ errorReported = reportWideningErrorsInType(c, s);
435
+ if (errorReported)
436
+ continue;
437
+ // Property types can come from object literal normalization in unions.
438
+ let valueDeclaration;
439
+ for (const d of p.declarations) {
440
+ const v = getSymbol(d)?.valueDeclaration;
441
+ if (v !== undefined && v.parent === t.symbol?.valueDeclaration) {
442
+ valueDeclaration = d;
443
+ break;
444
+ }
445
+ }
446
+ if (valueDeclaration !== undefined) {
447
+ c.error(valueDeclaration, 1690 /* Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type */, symbolToString(c, p), typeToString(c, getWidenedType(c, s)));
448
+ errorReported = true;
449
+ }
450
+ }
451
+ }
452
+ return errorReported;
453
+ }
454
+ export function reportImplicitAny(c, declaration, t, wideningKind = 0 /* WideningKind.Normal */) {
455
+ const file = getSourceFileOfNode(declaration);
456
+ // Only TypeScript files and checked JavaScript files report implicit `any`.
457
+ if (isInJSFile(declaration) && !isCheckJsEnabledForFile(file, c.compilerOptions))
458
+ return;
459
+ const typeAsString = typeToString(c, getWidenedType(c, t));
460
+ let message;
461
+ switch (declaration.kind) {
462
+ case 227 /* SyntaxKind.BinaryExpression */:
463
+ case 173 /* SyntaxKind.PropertyDeclaration */:
464
+ case 172 /* SyntaxKind.PropertySignature */:
465
+ message = c.noImplicitAny
466
+ ? 1680 /* Diagnostics.Member_0_implicitly_has_an_1_type */
467
+ : 1716 /* Diagnostics.Member_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage */;
468
+ break;
469
+ case 170 /* SyntaxKind.Parameter */: {
470
+ const isRest = getDotDotDotToken(declaration) !== undefined;
471
+ // `(string) => void` most likely meant a parameter of type `string`.
472
+ const name = getName(declaration);
473
+ const parent = declaration.parent;
474
+ if (name !== undefined &&
475
+ name.kind === 79 /* SyntaxKind.Identifier */ &&
476
+ (parent.kind === 180 /* SyntaxKind.CallSignature */ ||
477
+ parent.kind === 174 /* SyntaxKind.MethodSignature */ ||
478
+ parent.kind === 185 /* SyntaxKind.FunctionType */)) {
479
+ const index = getParameters(parent).nodes.indexOf(declaration);
480
+ const text = getText(name);
481
+ if (index >= 0 &&
482
+ (isTypeNodeKind(identifierToKeywordKind(text)) ||
483
+ resolveName(c, declaration, text, 788968 /* SymbolFlags.Type */, undefined, true, false) !== undefined)) {
484
+ c.addErrorOrSuggestion(c.noImplicitAny, createDiagnosticForNode(declaration, 1722 /* Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1 */, [
485
+ 'arg' + index,
486
+ declarationNameToString(file, name) + (isRest ? '[]' : ''),
487
+ ]));
488
+ return;
489
+ }
490
+ }
491
+ if (isRest)
492
+ message = c.noImplicitAny
493
+ ? 1691 /* Diagnostics.Rest_parameter_0_implicitly_has_an_any_type */
494
+ : 1718 /* Diagnostics.Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage */;
495
+ else
496
+ message = c.noImplicitAny
497
+ ? 1679 /* Diagnostics.Parameter_0_implicitly_has_an_1_type */
498
+ : 1715 /* Diagnostics.Parameter_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage */;
499
+ break;
500
+ }
501
+ case 209 /* SyntaxKind.BindingElement */:
502
+ if (!c.noImplicitAny)
503
+ return;
504
+ message = 1702 /* Diagnostics.Binding_element_0_implicitly_has_an_1_type */;
505
+ break;
506
+ case 263 /* SyntaxKind.FunctionDeclaration */:
507
+ case 175 /* SyntaxKind.MethodDeclaration */:
508
+ case 174 /* SyntaxKind.MethodSignature */:
509
+ case 178 /* SyntaxKind.GetAccessor */:
510
+ case 179 /* SyntaxKind.SetAccessor */:
511
+ case 219 /* SyntaxKind.FunctionExpression */:
512
+ case 220 /* SyntaxKind.ArrowFunction */:
513
+ if (c.noImplicitAny && getName(declaration) === undefined) {
514
+ c.error(declaration, wideningKind === 3 /* WideningKind.GeneratorYield */
515
+ ? 1696 /* Diagnostics.Generator_implicitly_has_yield_type_0_Consider_supplying_a_return_type_annotation */
516
+ : 1683 /* Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type */, typeAsString);
517
+ return;
518
+ }
519
+ if (c.noImplicitAny && (declaration.flags & 8 /* NodeFlags.Reparsed */) !== 0) {
520
+ c.error(declaration, 1684 /* Diagnostics.This_overload_implicitly_returns_the_type_0_because_it_lacks_a_return_type_annotation */, typeAsString);
521
+ return;
522
+ }
523
+ if (!c.noImplicitAny)
524
+ message = 1721 /* Diagnostics.X_0_implicitly_has_an_1_return_type_but_a_better_type_may_be_inferred_from_usage */;
525
+ else if (wideningKind === 3 /* WideningKind.GeneratorYield */)
526
+ message = 1726 /* Diagnostics.X_0_which_lacks_return_type_annotation_implicitly_has_an_1_yield_type */;
527
+ else
528
+ message = 1682 /* Diagnostics.X_0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type */;
529
+ break;
530
+ case 201 /* SyntaxKind.MappedType */:
531
+ if (c.noImplicitAny)
532
+ c.error(declaration, 1710 /* Diagnostics.Mapped_object_type_implicitly_has_an_any_template_type */);
533
+ return;
534
+ default:
535
+ message = c.noImplicitAny
536
+ ? 1678 /* Diagnostics.Variable_0_implicitly_has_an_1_type */
537
+ : 1714 /* Diagnostics.Variable_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage */;
538
+ }
539
+ const name = getNameOfDeclaration(declaration);
540
+ c.addErrorOrSuggestion(c.noImplicitAny, createDiagnosticForNode(declaration, message, [declarationNameToString(file, name), typeAsString]));
541
+ }
542
+ // ---- Widening
543
+ export function getWidenedType(c, t) {
544
+ return getWidenedTypeWithContext(c, t, undefined);
545
+ }
546
+ /** Widening state for the constituents of a union: object literals get each other's missing properties. */
547
+ class WideningContext {
548
+ parent;
549
+ propertyName;
550
+ siblings;
551
+ resolvedProperties = undefined;
552
+ /** The contexts of the properties, by name, shared by the object literals widened in this one. */
553
+ childContexts = undefined;
554
+ /** The widened types of the object literals widened in this context, for child contexts. */
555
+ widenedTypes = undefined;
556
+ constructor(parent, propertyName, siblings) {
557
+ this.parent = parent;
558
+ this.propertyName = propertyName;
559
+ this.siblings = siblings;
560
+ }
561
+ getChildContext(propertyName) {
562
+ this.childContexts ??= new Map();
563
+ let result = this.childContexts.get(propertyName);
564
+ if (result === undefined) {
565
+ result = new WideningContext(this, propertyName, undefined);
566
+ this.childContexts.set(propertyName, result);
567
+ }
568
+ return result;
569
+ }
570
+ }
571
+ function getWidenedTypeWithContext(c, t, context) {
572
+ if ((t.objectFlags & 196608 /* ObjectFlags.RequiresWidening */) === 0)
573
+ return t;
574
+ const key = cachedTypeKey(13 /* CachedTypeKind.Widened */, t.id);
575
+ if (context === undefined) {
576
+ const cached = c.cachedTypesById.get(key);
577
+ if (cached !== undefined)
578
+ return cached;
579
+ }
580
+ let result;
581
+ if ((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */)) !== 0)
582
+ result = c.anyType;
583
+ else if ((t.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0 && (t.flags & 1048576 /* TypeFlags.Object */) !== 0)
584
+ result = getWidenedTypeOfObjectLiteral(c, t, context);
585
+ else if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0) {
586
+ const unionContext = context ?? new WideningContext(undefined, '', typesOf(t));
587
+ const widened = [];
588
+ for (const u of typesOf(t))
589
+ widened.push((u.flags & 12 /* TypeFlags.Nullable */) !== 0 ? u : getWidenedTypeWithContext(c, u, unionContext));
590
+ // Widened empty object literals reduce subtypes, e.g. {} | string to {}.
591
+ result = getUnionTypeEx(c, widened, someEmptyObjectType(c, widened) ? 2 /* UnionReduction.Subtype */ : 1 /* UnionReduction.Literal */, undefined, undefined);
592
+ }
593
+ else if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
594
+ result = getIntersectionType(c, getWidenedTypes(c, typesOf(t)));
595
+ else if (isArrayOrTupleType(c, t))
596
+ result = createTypeReference(c, t.target, getWidenedTypes(c, getTypeArguments(c, t)));
597
+ if (result !== undefined && context === undefined)
598
+ c.cachedTypesById.set(key, result);
599
+ return result ?? t;
600
+ }
601
+ function getWidenedTypes(c, types) {
602
+ const result = [];
603
+ for (const t of types)
604
+ result.push(getWidenedType(c, t));
605
+ return result;
606
+ }
607
+ function someEmptyObjectType(c, types) {
608
+ for (const t of types)
609
+ if (isEmptyObjectType(c, t))
610
+ return true;
611
+ return false;
612
+ }
613
+ function getWidenedTypeOfObjectLiteral(c, t, context) {
614
+ const cached = context?.widenedTypes?.get(t);
615
+ if (cached !== undefined)
616
+ return cached;
617
+ const members = new Map();
618
+ for (const prop of getPropertiesOfObjectType(c, t))
619
+ members.set(prop.name, getWidenedProperty(c, prop, context));
620
+ if (context !== undefined)
621
+ for (const prop of getPropertiesOfContext(c, context))
622
+ if (!members.has(prop.name))
623
+ members.set(prop.name, getUndefinedProperty(c, prop));
624
+ const infos = getIndexInfosOfType(c, t).map((info) => new IndexInfo(info.keyType, getWidenedType(c, info.valueType), info.isReadonly, info.declaration, info.components));
625
+ const result = createAnonymousType(c, t.symbol, members, [], [], infos);
626
+ result.objectFlags |= t.objectFlags & (4096 /* ObjectFlags.JSLiteral */ | 262144 /* ObjectFlags.NonInferrableType */);
627
+ // The root context widens each object literal once; a property's context may widen one literal
628
+ // for several siblings.
629
+ if (context !== undefined && context.parent !== undefined) {
630
+ context.widenedTypes ??= new Map();
631
+ context.widenedTypes.set(t, result);
632
+ }
633
+ return result;
634
+ }
635
+ function getWidenedProperty(c, prop, context) {
636
+ if ((prop.flags & 4 /* SymbolFlags.Property */) === 0)
637
+ return prop;
638
+ const original = getTypeOfSymbol(c, prop);
639
+ const propContext = context?.getChildContext(prop.name);
640
+ const widened = getWidenedTypeWithContext(c, original, propContext);
641
+ if (widened === original)
642
+ return prop;
643
+ return createSymbolWithWidenedType(c, prop, widened);
644
+ }
645
+ function createSymbolWithWidenedType(c, prop, t) {
646
+ const result = c.newSymbolWithCheckFlags(prop.flags, prop.name, prop.checkFlags & 8 /* CheckFlags.Readonly */);
647
+ result.declarations = prop.declarations;
648
+ result.parent = prop.parent;
649
+ result.valueDeclaration = prop.valueDeclaration;
650
+ const id = getSymbolId(result);
651
+ c.symbolTypes.set(id, t);
652
+ c.symbolTargets.set(id, prop);
653
+ c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
654
+ return result;
655
+ }
656
+ /**
657
+ * An optional `undefined` property standing in for `prop`, the last property of that name among the
658
+ * sibling object literals (getPropertiesOfContext). It carries the declarations of the property it is
659
+ * created from, which order it among the members when they are printed.
660
+ *
661
+ * tsgo caches one such symbol per name and checker, so the declarations come from the first literal
662
+ * its checker widened with that name missing in a sibling. Its checkers check the program's files
663
+ * round robin, each file from the top. tsc-ts's checkers take files in another order, and a checker
664
+ * can infer a file's functions for an importer before it checks the file, so the first union is found
665
+ * in the sources of the files tsgo checks with the checker of the property's file, up to that file
666
+ * (`firstSiblingProperty`), which doesn't depend on the order of checking. Without one, the property
667
+ * is cached per sibling property. The order differs from tsgo's where tsgo's checker first infers a
668
+ * function of a file of another checker, or a later function of the file.
669
+ */
670
+ function getUndefinedProperty(c, prop) {
671
+ const member = prop.declarations.length > 0 ? firstSiblingProperty(c, prop.declarations[0], prop.name) : undefined;
672
+ const first = member !== undefined ? getSymbol(member) : undefined;
673
+ const source = first ?? prop;
674
+ const key = getSymbolId(source);
675
+ const cached = c.undefinedProperties.get(key);
676
+ if (cached !== undefined)
677
+ return cached;
678
+ const result = createSymbolWithWidenedType(c, source, c.undefinedOrMissingType);
679
+ result.flags |= 16777216 /* SymbolFlags.Optional */;
680
+ // The properties of a literal in an `as const` assertion are readonly.
681
+ if (first !== undefined && isInConstAssertion(member.parent))
682
+ result.checkFlags |= 8 /* CheckFlags.Readonly */;
683
+ c.undefinedProperties.set(key, result);
684
+ return result;
685
+ }
686
+ /**
687
+ * The property of `name` in the first union of object literals that leaves `name` missing in one of
688
+ * them, among the files tsgo checks with the checker of the declaration's file, up to that file: the
689
+ * last literal's property of that name. tsgo's checker `k` checks files `k`, `k + n`, `k + 2n`, ...
690
+ * in order (`tsgoCheckerSlots`). Unions are those of the returned expressions of a function without
691
+ * a return type, and of the alternatives of an initializer without a type (`?:`, `||`, `??`, array
692
+ * elements, an element access of an array literal, and the values of a property across the literals),
693
+ * of the variables of a `for...of`, of the object of a method call and of the expression of a type
694
+ * assertion. In a file, they are taken in the order a checker checking the file from the top widens
695
+ * them (`SiblingPropertyScan`).
696
+ */
697
+ function firstSiblingProperty(c, declaration, name) {
698
+ const file = getSourceFileOfNode(declaration);
699
+ const index = c.fileIndex.get(file);
700
+ if (index === undefined)
701
+ return siblingPropertiesOfFile(c, file).get(name);
702
+ const slots = tsgoCheckerSlots(c);
703
+ let slot = c.slotSiblingProperties.get(index % slots);
704
+ if (slot === undefined) {
705
+ slot = new SlotSiblingProperties(index % slots);
706
+ c.slotSiblingProperties.set(index % slots, slot);
707
+ }
708
+ for (; slot.next <= index; slot.next += slots)
709
+ for (const [n, member] of siblingPropertiesOfFile(c, c.files[slot.next]))
710
+ if (!slot.members.has(n)) {
711
+ slot.members.set(n, member);
712
+ slot.fileIndexes.set(n, slot.next);
713
+ }
714
+ const found = slot.fileIndexes.get(name);
715
+ return found !== undefined && found <= index ? slot.members.get(name) : undefined;
716
+ }
717
+ /**
718
+ * By name, the first property of the unions of `file` that leave the name missing: what a parse thread
719
+ * found (`SourceFile.siblingProperties`), or else the checker's own scan.
720
+ */
721
+ function siblingPropertiesOfFile(c, file) {
722
+ // A parse thread's scan takes array literals to have the global Array type.
723
+ if (file.siblingProperties !== undefined && c.globalArrayType !== c.emptyGenericType)
724
+ return file.siblingProperties;
725
+ let first = c.firstSiblingProperties.get(file);
726
+ if (first === undefined) {
727
+ first = scanSiblingProperties(file, c);
728
+ c.firstSiblingProperties.set(file, first);
729
+ }
730
+ return first;
731
+ }
732
+ /**
733
+ * By name, the first property of the unions of `file`'s object literals that leave the name missing.
734
+ * Without a checker, as on a parse thread, array literals are taken to have the global Array type, and
735
+ * the result is undefined where an enum the scan can't resolve decides which literals subtype reduction
736
+ * leaves out (`enumKeyOfMemberAccess`); the checker then scans the file itself.
737
+ */
738
+ export function scanSiblingProperties(file, c) {
739
+ if (file.isDeclarationFile)
740
+ return new Map();
741
+ const scan = new SiblingPropertyScan(c);
742
+ file.forEachChild(scan);
743
+ scan.widenAll();
744
+ return scan.unresolved ? undefined : scan.members;
745
+ }
746
+ /** The first property of each name among the files of one of tsgo's checkers, scanned in order. */
747
+ export class SlotSiblingProperties {
748
+ members = new Map();
749
+ /** The index of the file of each name's property. */
750
+ fileIndexes = new Map();
751
+ /** The index of the next file of the checker to scan. */
752
+ next;
753
+ constructor(first) {
754
+ this.next = first;
755
+ }
756
+ }
757
+ /** Whether an object literal is in an `as const` assertion, through arrays, spreads and properties. */
758
+ function isInConstAssertion(literal) {
759
+ for (let node = literal; node.parent !== undefined; node = node.parent) {
760
+ switch (node.parent.kind) {
761
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
762
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
763
+ case 231 /* SyntaxKind.SpreadElement */:
764
+ case 303 /* SyntaxKind.PropertyAssignment */:
765
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
766
+ continue;
767
+ case 235 /* SyntaxKind.AsExpression */:
768
+ case 217 /* SyntaxKind.TypeAssertionExpression */:
769
+ return isConstTypeReference(getType(node.parent));
770
+ }
771
+ return false;
772
+ }
773
+ return false;
774
+ }
775
+ /** An expression whose type is widened, at the position where a checker widens it. */
776
+ class WideningRoot {
777
+ position;
778
+ func;
779
+ alternatives;
780
+ sources;
781
+ calls;
782
+ constructor(position,
783
+ /** The function whose returned expressions these are, widened once. */
784
+ func,
785
+ /** The expressions whose types are unioned and widened. */
786
+ alternatives,
787
+ /** The expressions whose calls, innermost first, infer their functions' return types before. */
788
+ sources,
789
+ /** The calls of `sources` that may call a function of the file (`SiblingPropertyScan.callees`). */
790
+ calls = undefined) {
791
+ this.position = position;
792
+ this.func = func;
793
+ this.alternatives = alternatives;
794
+ this.sources = sources;
795
+ this.calls = calls;
796
+ }
797
+ }
798
+ /**
799
+ * The unions a checker widens while checking the file's statements or the body of one deferred function, and
800
+ * the deferred functions it queues there.
801
+ */
802
+ class CheckScope {
803
+ position;
804
+ roots = [];
805
+ deferred = [];
806
+ /** The calls by a name (`calleeName`), which infer where they end. */
807
+ calls = [];
808
+ constructor(position) {
809
+ this.position = position;
810
+ }
811
+ }
812
+ /**
813
+ * Whether a checker checks `node`'s body only as a deferred node: a function expression, arrow
814
+ * function or object literal method or accessor whose return type is written. Without one, the
815
+ * checker infers the return type where it reaches the function, from the returned expressions and
816
+ * what they refer to.
817
+ */
818
+ function isDeferredCheck(node) {
819
+ switch (node.kind) {
820
+ case 219 /* SyntaxKind.FunctionExpression */:
821
+ case 220 /* SyntaxKind.ArrowFunction */:
822
+ return getType(node) !== undefined;
823
+ case 175 /* SyntaxKind.MethodDeclaration */:
824
+ case 178 /* SyntaxKind.GetAccessor */:
825
+ return node.parent?.kind === 211 /* SyntaxKind.ObjectLiteralExpression */ && getType(node) !== undefined;
826
+ case 179 /* SyntaxKind.SetAccessor */:
827
+ return node.parent?.kind === 211 /* SyntaxKind.ObjectLiteralExpression */;
828
+ }
829
+ return false;
830
+ }
831
+ /**
832
+ * Finds the unions of a file's object literals in the order a checker widens them: an initializer
833
+ * where it is, and a function's returned expressions at its first `return`, where the checker
834
+ * infers its return type. A call of a function of the file, by a name that resolves to it or as
835
+ * `this.name(...)` in a class, infers that function's return type where the call is, and before the
836
+ * union of the expression the call is in. The bodies of function expressions, arrow functions and
837
+ * object literal methods and accessors with a written return type are checked after the file's
838
+ * statements, so their unions widen then.
839
+ */
840
+ class SiblingPropertyScan extends NodeVisitor {
841
+ /** The checker that resolves imported enums, or undefined on a parse thread. */
842
+ c;
843
+ /** By name, the property of the first union that leaves the name missing in a literal. */
844
+ members = new Map();
845
+ /**
846
+ * Whether array literals have an array type, whose elements are widened as one union. Without the
847
+ * global Array type (--noLib) an array literal is an empty object type.
848
+ */
849
+ arrays;
850
+ /** Whether an enum the scan can't resolve without a checker decided which literals were left out. */
851
+ unresolved = false;
852
+ /** The enums of the members that values refer to, numbered in the order the scan meets them. */
853
+ enums = new Map();
854
+ fileScope = new CheckScope(0);
855
+ /** The scope of the innermost deferred function around the node being visited. */
856
+ scope = this.fileScope;
857
+ /** The returned expressions of each function without a return type. */
858
+ returned = new Map();
859
+ /** The names a call can call those functions by (`functionName`). */
860
+ callees = new Set();
861
+ widened = new Set();
862
+ /** The functions and methods of each class, by name. */
863
+ classFunctions = new Map();
864
+ constructor(c) {
865
+ super();
866
+ this.c = c;
867
+ this.arrays = c === undefined || c.globalArrayType !== c.emptyGenericType;
868
+ }
869
+ /** The key of the values that are members of `symbol`, an enum, in this scan. */
870
+ enumKey(symbol) {
871
+ let id = this.enums.get(symbol);
872
+ if (id === undefined) {
873
+ id = this.enums.size;
874
+ this.enums.set(symbol, id);
875
+ }
876
+ return 'enum ' + id;
877
+ }
878
+ visitNode(node) {
879
+ switch (node.kind) {
880
+ case 263 /* SyntaxKind.FunctionDeclaration */:
881
+ case 219 /* SyntaxKind.FunctionExpression */:
882
+ case 220 /* SyntaxKind.ArrowFunction */:
883
+ case 175 /* SyntaxKind.MethodDeclaration */:
884
+ case 178 /* SyntaxKind.GetAccessor */: {
885
+ const body = getBody(node);
886
+ if (body === undefined || getType(node) !== undefined)
887
+ break;
888
+ const returned = [];
889
+ const sources = [];
890
+ let position = body.pos;
891
+ if (body.kind === 242 /* SyntaxKind.Block */) {
892
+ const collector = new ReturnCollector();
893
+ collector.visitStatements(body);
894
+ if (collector.returns.length > 0)
895
+ position = collector.returns[0].pos;
896
+ for (const r of collector.returns)
897
+ if (r.expression !== undefined) {
898
+ addAlternatives(r.expression, returned, this.arrays);
899
+ sources.push(r.expression);
900
+ }
901
+ }
902
+ else {
903
+ addAlternatives(body, returned, this.arrays);
904
+ sources.push(body);
905
+ }
906
+ if (returned.length === 0)
907
+ break;
908
+ const root = new WideningRoot(position, node, returned, sources);
909
+ this.returned.set(node, root);
910
+ this.addRoot(root);
911
+ if (node.kind === 175 /* SyntaxKind.MethodDeclaration */ || node.kind === 178 /* SyntaxKind.GetAccessor */)
912
+ this.addClassFunction(node, node);
913
+ break;
914
+ }
915
+ case 261 /* SyntaxKind.VariableDeclaration */:
916
+ case 173 /* SyntaxKind.PropertyDeclaration */:
917
+ case 170 /* SyntaxKind.Parameter */: {
918
+ const initializer = getInitializer(node);
919
+ if (initializer === undefined || getType(node) !== undefined)
920
+ break;
921
+ this.addRoot(new WideningRoot(initializer.pos, undefined, addAlternatives(initializer, [], this.arrays), [initializer]));
922
+ const value = skipParentheses(initializer);
923
+ if (node.kind === 173 /* SyntaxKind.PropertyDeclaration */ &&
924
+ (value.kind === 220 /* SyntaxKind.ArrowFunction */ || value.kind === 219 /* SyntaxKind.FunctionExpression */))
925
+ this.addClassFunction(node, value);
926
+ break;
927
+ }
928
+ case 278 /* SyntaxKind.ExportAssignment */:
929
+ if (getType(node) === undefined) {
930
+ const expression = getExpression(node);
931
+ this.addRoot(new WideningRoot(node.pos, undefined, addAlternatives(expression, [], this.arrays), [expression]));
932
+ }
933
+ break;
934
+ case 251 /* SyntaxKind.ForOfStatement */: {
935
+ // The variable of `for (const x of e)` has the widened type of e's elements, and each element
936
+ // of a binding pattern the widened type of its part of them.
937
+ const statement = node;
938
+ if (statement.initializer.kind !== 262 /* SyntaxKind.VariableDeclarationList */)
939
+ break;
940
+ const declaration = statement.initializer.declarations.nodes[0];
941
+ if (declaration === undefined || getType(declaration) !== undefined || !this.arrays)
942
+ break;
943
+ const elements = [];
944
+ for (const array of iteratedArrayLiterals(statement.expression))
945
+ addArrayElements(array, elements);
946
+ if (elements.length === 0)
947
+ break;
948
+ for (const alternatives of bindingAlternatives(getName(declaration), elements))
949
+ this.addRoot(new WideningRoot(statement.expression.pos, undefined, alternatives, [statement.expression]));
950
+ break;
951
+ }
952
+ case 214 /* SyntaxKind.CallExpression */: {
953
+ // The object of a method call is widened before the call is resolved.
954
+ const callee = skipParentheses(getExpression(node));
955
+ if ((callee.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || callee.kind === 213 /* SyntaxKind.ElementAccessExpression */) &&
956
+ mayHoldLiterals(getExpression(callee)))
957
+ this.addExpressionRoot(callee.pos, getExpression(callee));
958
+ // Calls elsewhere, as in statements, infer where they end.
959
+ if (calleeName(node) !== undefined)
960
+ this.scope.calls.push(node);
961
+ break;
962
+ }
963
+ }
964
+ if (isTypeNodeKind(node.kind))
965
+ return false;
966
+ if ((node.kind === 235 /* SyntaxKind.AsExpression */ || node.kind === 217 /* SyntaxKind.TypeAssertionExpression */) &&
967
+ !isConstTypeReference(getType(node))) {
968
+ // An assertion widens its expression's type in a deferred check, queued after the expression's.
969
+ node.forEachChild(this);
970
+ const inner = new CheckScope(node.end);
971
+ this.scope.deferred.push(inner);
972
+ const saveScope = this.scope;
973
+ this.scope = inner;
974
+ this.addExpressionRoot(node.end, getExpression(node));
975
+ this.scope = saveScope;
976
+ return false;
977
+ }
978
+ if (isDeferredCheck(node)) {
979
+ const inner = new CheckScope(node.pos);
980
+ this.scope.deferred.push(inner);
981
+ const saveScope = this.scope;
982
+ this.scope = inner;
983
+ node.forEachChild(this);
984
+ this.scope = saveScope;
985
+ }
986
+ else
987
+ node.forEachChild(this);
988
+ return false;
989
+ }
990
+ addRoot(root) {
991
+ this.scope.roots.push(root);
992
+ }
993
+ /** Adds a root for the widened type of `expression` where it holds object or array literals. */
994
+ addExpressionRoot(position, expression) {
995
+ const alternatives = addAlternatives(expression, [], this.arrays);
996
+ if (alternatives.some((a) => a.kind === 211 /* SyntaxKind.ObjectLiteralExpression */ || a.kind === 210 /* SyntaxKind.ArrayLiteralExpression */))
997
+ this.addRoot(new WideningRoot(position, undefined, alternatives, [expression]));
998
+ }
999
+ /** Names `func` in its class by `member`, a method or a property it initializes. */
1000
+ addClassFunction(member, func) {
1001
+ const name = getName(member);
1002
+ const parent = member.parent;
1003
+ if (name === undefined || name.kind !== 79 /* SyntaxKind.Identifier */)
1004
+ return;
1005
+ if (parent.kind !== 264 /* SyntaxKind.ClassDeclaration */ && parent.kind !== 232 /* SyntaxKind.ClassExpression */)
1006
+ return;
1007
+ let functions = this.classFunctions.get(parent);
1008
+ if (functions === undefined)
1009
+ this.classFunctions.set(parent, (functions = new Map()));
1010
+ if (!functions.has(getText(name)))
1011
+ functions.set(getText(name), func);
1012
+ }
1013
+ /**
1014
+ * Widens the unions of the file's statements in order, then those of each deferred node in the
1015
+ * order the checker queues them, which includes the deferred nodes queued while checking one.
1016
+ */
1017
+ widenAll() {
1018
+ for (const func of this.returned.keys()) {
1019
+ const name = functionName(func);
1020
+ if (name !== undefined)
1021
+ this.callees.add(name);
1022
+ }
1023
+ const queue = [this.fileScope];
1024
+ for (let i = 0; i < queue.length; i++) {
1025
+ const scope = queue[i];
1026
+ if (this.callees.size !== 0)
1027
+ for (const call of scope.calls)
1028
+ if (this.callees.has(calleeName(call)))
1029
+ scope.roots.push(new WideningRoot(call.end, undefined, [], [], [call]));
1030
+ scope.roots.sort((a, b) => a.position - b.position);
1031
+ scope.deferred.sort((a, b) => a.position - b.position);
1032
+ let next = 0;
1033
+ for (const root of scope.roots) {
1034
+ while (next < scope.deferred.length && scope.deferred[next].position < root.position)
1035
+ queue.push(scope.deferred[next++]);
1036
+ this.widenRoot(root);
1037
+ }
1038
+ while (next < scope.deferred.length)
1039
+ queue.push(scope.deferred[next++]);
1040
+ }
1041
+ }
1042
+ /** Widens a root's unions, after the returned expressions of the functions its calls infer. */
1043
+ widenRoot(root) {
1044
+ if (root.func !== undefined) {
1045
+ if (this.widened.has(root.func))
1046
+ return;
1047
+ this.widened.add(root.func);
1048
+ }
1049
+ if (this.callees.size === 0) {
1050
+ this.widen(root.alternatives, true);
1051
+ return;
1052
+ }
1053
+ if (root.calls === undefined) {
1054
+ const collector = new CallCollector(this.callees);
1055
+ for (const source of root.sources)
1056
+ collector.visitNode(source);
1057
+ root.calls = collector.calls;
1058
+ }
1059
+ for (const call of root.calls) {
1060
+ const callee = this.calledFunction(call);
1061
+ const returned = callee !== undefined ? this.returned.get(callee) : undefined;
1062
+ if (returned !== undefined)
1063
+ this.widenRoot(returned);
1064
+ }
1065
+ this.widen(root.alternatives, true);
1066
+ }
1067
+ /**
1068
+ * The function a call calls: a function declaration or a variable initialized with a function that
1069
+ * the callee's name resolves to (`getLocals` of the scopes around the call), or a method or property
1070
+ * of the class for `this.name(...)` in a class member.
1071
+ */
1072
+ calledFunction(call) {
1073
+ const callee = skipParentheses(getExpression(call));
1074
+ if (callee.kind === 79 /* SyntaxKind.Identifier */) {
1075
+ const name = getText(callee);
1076
+ for (let scope = call.parent; scope !== undefined; scope = scope.parent) {
1077
+ const symbol = getLocals(scope)?.get(name);
1078
+ // A type alias, interface or type parameter of the name doesn't hide a value of an outer scope.
1079
+ if (symbol === undefined || (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) === 0)
1080
+ continue;
1081
+ // An exported declaration's local symbol has no value declaration of its own.
1082
+ const declaration = symbol.valueDeclaration ??
1083
+ symbol.declarations.find((d) => d.kind === 263 /* SyntaxKind.FunctionDeclaration */ || d.kind === 261 /* SyntaxKind.VariableDeclaration */);
1084
+ if (declaration === undefined)
1085
+ return undefined;
1086
+ if (declaration.kind === 263 /* SyntaxKind.FunctionDeclaration */)
1087
+ return declaration;
1088
+ const initializer = declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ ? getInitializer(declaration) : undefined;
1089
+ const value = initializer !== undefined ? skipParentheses(initializer) : undefined;
1090
+ return value !== undefined &&
1091
+ (value.kind === 220 /* SyntaxKind.ArrowFunction */ || value.kind === 219 /* SyntaxKind.FunctionExpression */)
1092
+ ? value
1093
+ : undefined;
1094
+ }
1095
+ return undefined;
1096
+ }
1097
+ if (callee.kind !== 212 /* SyntaxKind.PropertyAccessExpression */ || getExpression(callee).kind !== 109 /* SyntaxKind.ThisKeyword */)
1098
+ return undefined;
1099
+ const name = getName(callee);
1100
+ const container = thisClass(call);
1101
+ const functions = container !== undefined ? this.classFunctions.get(container) : undefined;
1102
+ return functions !== undefined && name.kind === 79 /* SyntaxKind.Identifier */ ? functions.get(getText(name)) : undefined;
1103
+ }
1104
+ /**
1105
+ * Records the unions of the alternatives of one widened expression, and of their nested values.
1106
+ * With `reduced`, the alternatives make up one union with subtype reduction (the alternatives of an
1107
+ * expression, the elements of an array literal), which drops a literal whose widened type is the
1108
+ * type of an earlier one (`removeSubtypes` removes the later of two identical types). The values of
1109
+ * a property across literals are not reduced: their union is one of each literal's value.
1110
+ */
1111
+ widen(alternatives, reduced) {
1112
+ let literals = [];
1113
+ for (const a of alternatives)
1114
+ if (a.kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
1115
+ literals.push(a);
1116
+ // The elements of a tuple, an array literal in an `as const` assertion, widen separately.
1117
+ else if (this.arrays && a.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ && !isInConstAssertion(a))
1118
+ this.widen(addArrayElements(a, []), true);
1119
+ if (literals.length === 0)
1120
+ return;
1121
+ if (reduced)
1122
+ literals = withoutRepeatedLiterals(this, literals);
1123
+ if (literals.length > 1)
1124
+ this.record(literals);
1125
+ const values = new Map();
1126
+ for (const literal of literals)
1127
+ for (const member of literal.properties.nodes) {
1128
+ if (member.kind !== 303 /* SyntaxKind.PropertyAssignment */)
1129
+ continue;
1130
+ const name = staticPropertyName(member);
1131
+ if (name === undefined)
1132
+ continue;
1133
+ let list = values.get(name);
1134
+ if (list === undefined)
1135
+ values.set(name, (list = []));
1136
+ // A value's own alternatives make up one reduced union, one member of the property's values.
1137
+ const own = addAlternatives(member.initializer, [], this.arrays);
1138
+ for (const value of withoutRepeatedLiterals(this, own))
1139
+ list.push(value);
1140
+ }
1141
+ for (const list of values.values())
1142
+ this.widen(list, false);
1143
+ }
1144
+ /**
1145
+ * Records, for each name that some literal without a spread lacks, the last such literal's property
1146
+ * of that name, unless an earlier union has the name.
1147
+ */
1148
+ record(literals) {
1149
+ const plain = [];
1150
+ for (const literal of literals) {
1151
+ let members = new Map();
1152
+ for (const member of literal.properties.nodes) {
1153
+ if (member.kind === 305 /* SyntaxKind.SpreadAssignment */) {
1154
+ members = undefined;
1155
+ break;
1156
+ }
1157
+ const name = staticPropertyName(member);
1158
+ if (name !== undefined)
1159
+ members.set(name, member);
1160
+ }
1161
+ if (members !== undefined)
1162
+ plain.push(members);
1163
+ }
1164
+ const last = new Map();
1165
+ for (const members of plain)
1166
+ for (const [name, member] of members)
1167
+ last.set(name, member);
1168
+ for (const [name, member] of last) {
1169
+ // A method's or accessor's symbol has other flags than the property checkObjectLiteral makes of it.
1170
+ if (member.kind !== 303 /* SyntaxKind.PropertyAssignment */ && member.kind !== 304 /* SyntaxKind.ShorthandPropertyAssignment */)
1171
+ continue;
1172
+ if (this.members.has(name) || plain.every((members) => members.has(name)))
1173
+ continue;
1174
+ this.members.set(name, member);
1175
+ }
1176
+ }
1177
+ }
1178
+ /**
1179
+ * `nodes` without the object literals whose widened types are certainly those of an earlier one:
1180
+ * the same property names, each with a value of the same widened type (`widenedTypeKey`). Literals
1181
+ * that can have a contextual type are kept: it can keep their properties' literal types.
1182
+ */
1183
+ function withoutRepeatedLiterals(scan, nodes) {
1184
+ let keys;
1185
+ let result;
1186
+ for (let i = 0; i < nodes.length; i++) {
1187
+ const node = nodes[i];
1188
+ const key = node.kind === 211 /* SyntaxKind.ObjectLiteralExpression */ && !mayHaveContextualType(node)
1189
+ ? widenedTypeKey(scan, node)
1190
+ : undefined;
1191
+ if (key !== undefined) {
1192
+ if (keys === undefined)
1193
+ keys = [];
1194
+ else if (keys.includes(key)) {
1195
+ // Without a checker, an enum the scan can't resolve may or may not make the types the same.
1196
+ if (key.includes(pendingEnumKey))
1197
+ scan.unresolved = true;
1198
+ if (result === undefined)
1199
+ result = nodes.slice(0, i);
1200
+ continue;
1201
+ }
1202
+ keys.push(key);
1203
+ }
1204
+ result?.push(node);
1205
+ }
1206
+ return result ?? nodes;
1207
+ }
1208
+ /**
1209
+ * A key that two expressions of one file share only when their types widen to the same type, or
1210
+ * undefined where that isn't known from the syntax: literals by their widened type, members of an
1211
+ * enum by the enum, and object literals by their properties' names and keys. Other references can
1212
+ * name different symbols or be narrowed differently.
1213
+ */
1214
+ function widenedTypeKey(scan, node) {
1215
+ switch (node.kind) {
1216
+ case 10 /* SyntaxKind.StringLiteral */:
1217
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
1218
+ case 229 /* SyntaxKind.TemplateExpression */:
1219
+ return 'string';
1220
+ case 8 /* SyntaxKind.NumericLiteral */:
1221
+ return 'number';
1222
+ case 9 /* SyntaxKind.BigIntLiteral */:
1223
+ return 'bigint';
1224
+ case 111 /* SyntaxKind.TrueKeyword */:
1225
+ case 96 /* SyntaxKind.FalseKeyword */:
1226
+ return 'boolean';
1227
+ case 13 /* SyntaxKind.RegularExpressionLiteral */:
1228
+ return 'RegExp';
1229
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
1230
+ const unary = node;
1231
+ const operand = unary.operand.kind;
1232
+ if (unary.operator === 40 /* SyntaxKind.MinusToken */ || unary.operator === 39 /* SyntaxKind.PlusToken */) {
1233
+ if (operand === 8 /* SyntaxKind.NumericLiteral */)
1234
+ return 'number';
1235
+ if (operand === 9 /* SyntaxKind.BigIntLiteral */ && unary.operator === 40 /* SyntaxKind.MinusToken */)
1236
+ return 'bigint';
1237
+ }
1238
+ return undefined;
1239
+ }
1240
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
1241
+ return enumKeyOfMemberAccess(scan, node);
1242
+ case 211 /* SyntaxKind.ObjectLiteralExpression */: {
1243
+ const members = [];
1244
+ for (const member of node.properties.nodes) {
1245
+ if (member.kind !== 303 /* SyntaxKind.PropertyAssignment */)
1246
+ return undefined;
1247
+ const name = staticPropertyName(member);
1248
+ const value = widenedTypeKey(scan, member.initializer);
1249
+ if (name === undefined || value === undefined)
1250
+ return undefined;
1251
+ members.push(JSON.stringify(name) + ': ' + value);
1252
+ }
1253
+ members.sort();
1254
+ return '{' + members.join(', ') + '}';
1255
+ }
1256
+ }
1257
+ return undefined;
1258
+ }
1259
+ /** The key of a member of an enum that the scan can't resolve without a checker. */
1260
+ const pendingEnumKey = 'enum ?';
1261
+ /**
1262
+ * The key of `E.Member` where `E` names an enum in the scopes around the access (`getLocals`, as
1263
+ * `calledFunction` finds names) and `Member` is one of its members, not an export of a namespace merged
1264
+ * with it: the key of the enum. With a checker, `E` can be imported. Without one, an import, and a
1265
+ * global of a script file (whose enum other files can extend), give `pendingEnumKey`.
1266
+ */
1267
+ function enumKeyOfMemberAccess(scan, node) {
1268
+ const target = getExpression(node);
1269
+ const member = getName(node);
1270
+ if (target.kind !== 79 /* SyntaxKind.Identifier */ || member.kind !== 79 /* SyntaxKind.Identifier */)
1271
+ return undefined;
1272
+ const name = getText(target);
1273
+ const c = scan.c;
1274
+ for (let scope = node.parent; scope !== undefined; scope = scope.parent) {
1275
+ let symbol = getLocals(scope)?.get(name);
1276
+ if (symbol === undefined ||
1277
+ (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */ | 2097152 /* SymbolFlags.Alias */)) === 0)
1278
+ continue;
1279
+ if (c === undefined) {
1280
+ if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
1281
+ return pendingEnumKey;
1282
+ if ((symbol.flags & (384 /* SymbolFlags.Enum */ | 1536 /* SymbolFlags.Module */)) !== 0 &&
1283
+ !isExternalModule(getSourceFileOfNode(node)))
1284
+ return pendingEnumKey;
1285
+ }
1286
+ if (symbol.exportSymbol !== undefined)
1287
+ symbol = symbol.exportSymbol;
1288
+ if (c !== undefined) {
1289
+ symbol = getMergedSymbol(c, symbol);
1290
+ if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
1291
+ symbol = resolveAlias(c, symbol);
1292
+ }
1293
+ if ((symbol.flags & 384 /* SymbolFlags.Enum */) === 0)
1294
+ return undefined;
1295
+ // An enum merged with a namespace also exports the namespace's values.
1296
+ const memberSymbol = symbol.exports?.get(getText(member));
1297
+ return memberSymbol !== undefined && (memberSymbol.flags & 8 /* SymbolFlags.EnumMember */) !== 0
1298
+ ? scan.enumKey(symbol)
1299
+ : undefined;
1300
+ }
1301
+ return undefined;
1302
+ }
1303
+ /**
1304
+ * Whether an object literal of a widened expression can have a contextual type: under `satisfies`,
1305
+ * an assertion or an argument, as a parameter's default, or returned from a function that can have
1306
+ * a contextual signature (a function expression that doesn't initialize an untyped declaration, or a
1307
+ * method of an object literal). Initializers of untyped declarations, the returns of function
1308
+ * declarations and class members, and the objects of property and element accesses have none.
1309
+ */
1310
+ function mayHaveContextualType(node) {
1311
+ for (let current = node.parent; current !== undefined; current = current.parent) {
1312
+ switch (current.kind) {
1313
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
1314
+ case 236 /* SyntaxKind.NonNullExpression */:
1315
+ case 224 /* SyntaxKind.AwaitExpression */:
1316
+ case 228 /* SyntaxKind.ConditionalExpression */:
1317
+ case 227 /* SyntaxKind.BinaryExpression */:
1318
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
1319
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
1320
+ case 303 /* SyntaxKind.PropertyAssignment */:
1321
+ case 254 /* SyntaxKind.ReturnStatement */:
1322
+ case 242 /* SyntaxKind.Block */:
1323
+ case 246 /* SyntaxKind.IfStatement */:
1324
+ case 247 /* SyntaxKind.DoStatement */:
1325
+ case 248 /* SyntaxKind.WhileStatement */:
1326
+ case 249 /* SyntaxKind.ForStatement */:
1327
+ case 250 /* SyntaxKind.ForInStatement */:
1328
+ case 251 /* SyntaxKind.ForOfStatement */:
1329
+ case 256 /* SyntaxKind.SwitchStatement */:
1330
+ case 270 /* SyntaxKind.CaseBlock */:
1331
+ case 297 /* SyntaxKind.CaseClause */:
1332
+ case 298 /* SyntaxKind.DefaultClause */:
1333
+ case 257 /* SyntaxKind.LabeledStatement */:
1334
+ case 259 /* SyntaxKind.TryStatement */:
1335
+ case 300 /* SyntaxKind.CatchClause */:
1336
+ continue;
1337
+ case 261 /* SyntaxKind.VariableDeclaration */:
1338
+ case 173 /* SyntaxKind.PropertyDeclaration */:
1339
+ case 278 /* SyntaxKind.ExportAssignment */:
1340
+ case 263 /* SyntaxKind.FunctionDeclaration */:
1341
+ // The object of a property access, as in a method call, has no contextual type.
1342
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
1343
+ case 213 /* SyntaxKind.ElementAccessExpression */:
1344
+ return false;
1345
+ case 175 /* SyntaxKind.MethodDeclaration */:
1346
+ case 178 /* SyntaxKind.GetAccessor */: {
1347
+ const parent = current.parent.kind;
1348
+ return parent !== 264 /* SyntaxKind.ClassDeclaration */ && parent !== 232 /* SyntaxKind.ClassExpression */;
1349
+ }
1350
+ case 220 /* SyntaxKind.ArrowFunction */:
1351
+ case 219 /* SyntaxKind.FunctionExpression */: {
1352
+ let outer = current.parent;
1353
+ while (outer.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
1354
+ outer = outer.parent;
1355
+ return ((outer.kind !== 261 /* SyntaxKind.VariableDeclaration */ && outer.kind !== 173 /* SyntaxKind.PropertyDeclaration */) ||
1356
+ getType(outer) !== undefined);
1357
+ }
1358
+ default:
1359
+ return true;
1360
+ }
1361
+ }
1362
+ return true;
1363
+ }
1364
+ /** Collects the calls by one of `names` in an expression, innermost first, outside the functions in it. */
1365
+ class CallCollector extends NodeVisitor {
1366
+ names;
1367
+ calls = [];
1368
+ constructor(names) {
1369
+ super();
1370
+ this.names = names;
1371
+ }
1372
+ visitNode(node) {
1373
+ if (isFunctionLike(node) || node.kind === 232 /* SyntaxKind.ClassExpression */)
1374
+ return false;
1375
+ node.forEachChild(this);
1376
+ if (node.kind === 214 /* SyntaxKind.CallExpression */) {
1377
+ const name = calleeName(node);
1378
+ if (name !== undefined && this.names.has(name))
1379
+ this.calls.push(node);
1380
+ }
1381
+ return false;
1382
+ }
1383
+ }
1384
+ /** The name a call calls its function by, `f` in `f(...)` and `this.f(...)`, if the scan can resolve it. */
1385
+ function calleeName(call) {
1386
+ const callee = skipParentheses(getExpression(call));
1387
+ if (callee.kind === 79 /* SyntaxKind.Identifier */)
1388
+ return getText(callee);
1389
+ if (callee.kind !== 212 /* SyntaxKind.PropertyAccessExpression */ || getExpression(callee).kind !== 109 /* SyntaxKind.ThisKeyword */)
1390
+ return undefined;
1391
+ const name = getName(callee);
1392
+ return name.kind === 79 /* SyntaxKind.Identifier */ ? getText(name) : undefined;
1393
+ }
1394
+ /**
1395
+ * The name calls can call a function without a return type by: a function declaration's, a method's or
1396
+ * accessor's, or that of the variable or property a function expression initializes.
1397
+ */
1398
+ function functionName(func) {
1399
+ let node = func;
1400
+ if (func.kind === 219 /* SyntaxKind.FunctionExpression */ || func.kind === 220 /* SyntaxKind.ArrowFunction */) {
1401
+ while (node.parent?.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
1402
+ node = node.parent;
1403
+ if (node.parent?.kind !== 261 /* SyntaxKind.VariableDeclaration */ && node.parent?.kind !== 173 /* SyntaxKind.PropertyDeclaration */)
1404
+ return undefined;
1405
+ node = node.parent;
1406
+ }
1407
+ const name = getName(node);
1408
+ return name?.kind === 79 /* SyntaxKind.Identifier */ ? getText(name) : undefined;
1409
+ }
1410
+ /** Whether an expression's alternatives (`addAlternatives`) can hold object or array literals. */
1411
+ function mayHoldLiterals(node) {
1412
+ switch (skipParentheses(node).kind) {
1413
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
1414
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
1415
+ case 228 /* SyntaxKind.ConditionalExpression */:
1416
+ case 227 /* SyntaxKind.BinaryExpression */:
1417
+ case 236 /* SyntaxKind.NonNullExpression */:
1418
+ case 239 /* SyntaxKind.SatisfiesExpression */:
1419
+ case 224 /* SyntaxKind.AwaitExpression */:
1420
+ case 235 /* SyntaxKind.AsExpression */:
1421
+ case 217 /* SyntaxKind.TypeAssertionExpression */:
1422
+ return true;
1423
+ }
1424
+ return false;
1425
+ }
1426
+ /** The class whose instance `this` is at `node`, through arrow functions, in a member or property initializer. */
1427
+ function thisClass(node) {
1428
+ for (let current = node.parent; current !== undefined; current = current.parent) {
1429
+ if (current.kind === 220 /* SyntaxKind.ArrowFunction */)
1430
+ continue;
1431
+ if (current.kind === 175 /* SyntaxKind.MethodDeclaration */ ||
1432
+ current.kind === 178 /* SyntaxKind.GetAccessor */ ||
1433
+ current.kind === 179 /* SyntaxKind.SetAccessor */ ||
1434
+ current.kind === 177 /* SyntaxKind.Constructor */ ||
1435
+ current.kind === 173 /* SyntaxKind.PropertyDeclaration */) {
1436
+ const parent = current.parent;
1437
+ return parent.kind === 264 /* SyntaxKind.ClassDeclaration */ || parent.kind === 232 /* SyntaxKind.ClassExpression */
1438
+ ? parent
1439
+ : undefined;
1440
+ }
1441
+ if (isFunctionLike(current) || current.kind === 307 /* SyntaxKind.SourceFile */)
1442
+ return undefined;
1443
+ }
1444
+ return undefined;
1445
+ }
1446
+ /**
1447
+ * Adds the expressions whose types make up the type of `node`: both sides of `?:`, `||` and `??`,
1448
+ * and the elements of an array literal that `node` indexes when `arrays` (see SiblingPropertyScan).
1449
+ */
1450
+ function addAlternatives(node, out, arrays) {
1451
+ switch (node.kind) {
1452
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
1453
+ case 236 /* SyntaxKind.NonNullExpression */:
1454
+ case 239 /* SyntaxKind.SatisfiesExpression */:
1455
+ case 224 /* SyntaxKind.AwaitExpression */:
1456
+ return addAlternatives(getExpression(node), out, arrays);
1457
+ case 235 /* SyntaxKind.AsExpression */:
1458
+ case 217 /* SyntaxKind.TypeAssertionExpression */:
1459
+ // An object literal in an `as const` assertion is still an object literal type, with readonly
1460
+ // properties; an array literal in one is a tuple, whose elements widen separately.
1461
+ if (isConstAssertion(node) && skipParentheses(getExpression(node)).kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
1462
+ return addAlternatives(getExpression(node), out, arrays);
1463
+ break;
1464
+ case 228 /* SyntaxKind.ConditionalExpression */:
1465
+ addAlternatives(node.whenTrue, out, arrays);
1466
+ return addAlternatives(node.whenFalse, out, arrays);
1467
+ case 227 /* SyntaxKind.BinaryExpression */: {
1468
+ const binary = node;
1469
+ switch (binary.operatorToken.kind) {
1470
+ case 56 /* SyntaxKind.BarBarToken */:
1471
+ case 60 /* SyntaxKind.QuestionQuestionToken */:
1472
+ addAlternatives(binary.left, out, arrays);
1473
+ return addAlternatives(binary.right, out, arrays);
1474
+ case 55 /* SyntaxKind.AmpersandAmpersandToken */:
1475
+ case 27 /* SyntaxKind.CommaToken */:
1476
+ return addAlternatives(binary.right, out, arrays);
1477
+ }
1478
+ break;
1479
+ }
1480
+ case 213 /* SyntaxKind.ElementAccessExpression */: {
1481
+ // `[a, b][i]` has the type of the array's elements, which the declaration widens as one union.
1482
+ const array = skipParentheses(getExpression(node));
1483
+ if (!arrays || array.kind !== 210 /* SyntaxKind.ArrayLiteralExpression */)
1484
+ break;
1485
+ for (const e of array.elements.nodes)
1486
+ if (e.kind !== 231 /* SyntaxKind.SpreadElement */)
1487
+ addAlternatives(e, out, arrays);
1488
+ return out;
1489
+ }
1490
+ }
1491
+ out.push(node);
1492
+ return out;
1493
+ }
1494
+ /**
1495
+ * The alternatives of the elements of an array literal, whose types make its element type, with those
1496
+ * of the array literals that its spread elements spread. Used where array literals have an array type
1497
+ * (`SiblingPropertyScan.arrays`), as are `iteratedArrayLiterals` and `bindingAlternatives`.
1498
+ */
1499
+ function addArrayElements(array, out) {
1500
+ for (const e of array.elements.nodes)
1501
+ if (e.kind !== 231 /* SyntaxKind.SpreadElement */)
1502
+ addAlternatives(e, out, true);
1503
+ else
1504
+ for (const spread of addAlternatives(getExpression(e), [], true))
1505
+ if (spread.kind === 210 /* SyntaxKind.ArrayLiteralExpression */)
1506
+ addArrayElements(spread, out);
1507
+ return out;
1508
+ }
1509
+ /** The array literals whose elements a `for...of` over `expression` iterates, through `as const`. */
1510
+ function iteratedArrayLiterals(expression) {
1511
+ const arrays = [];
1512
+ for (const a of addAlternatives(expression, [], true)) {
1513
+ const value = isConstAssertion(a) ? skipParentheses(getExpression(a)) : a;
1514
+ if (value.kind === 210 /* SyntaxKind.ArrayLiteralExpression */)
1515
+ arrays.push(value);
1516
+ }
1517
+ return arrays;
1518
+ }
1519
+ function isConstAssertion(node) {
1520
+ return ((node.kind === 235 /* SyntaxKind.AsExpression */ || node.kind === 217 /* SyntaxKind.TypeAssertionExpression */) &&
1521
+ isConstTypeReference(getType(node)));
1522
+ }
1523
+ /**
1524
+ * The alternatives whose union each variable of a binding name is widened from, given the alternatives
1525
+ * of the iterated elements: all of them for an identifier; for an element of an array pattern, its
1526
+ * element of each `as const` array literal, or every element of another array literal; for an element
1527
+ * of an object pattern, the values of its property in each object literal.
1528
+ */
1529
+ function bindingAlternatives(name, elements) {
1530
+ if (name.kind === 79 /* SyntaxKind.Identifier */)
1531
+ return [elements];
1532
+ const result = [];
1533
+ const isArrayPattern = name.kind === 208 /* SyntaxKind.ArrayBindingPattern */;
1534
+ const bindings = name.elements.nodes;
1535
+ for (let k = 0; k < bindings.length; k++) {
1536
+ const binding = bindings[k];
1537
+ if (binding.kind !== 209 /* SyntaxKind.BindingElement */)
1538
+ continue;
1539
+ const element = binding;
1540
+ if (element.dotDotDotToken !== undefined || element.initializer !== undefined)
1541
+ continue;
1542
+ if (element.name?.kind !== 79 /* SyntaxKind.Identifier */)
1543
+ continue;
1544
+ const alternatives = [];
1545
+ if (isArrayPattern) {
1546
+ for (const e of elements) {
1547
+ const value = isConstAssertion(e) ? skipParentheses(getExpression(e)) : e;
1548
+ if (value.kind !== 210 /* SyntaxKind.ArrayLiteralExpression */)
1549
+ continue;
1550
+ const array = value;
1551
+ if (value !== e || isInConstAssertion(array)) {
1552
+ const item = array.elements.nodes[k];
1553
+ if (item !== undefined && item.kind !== 231 /* SyntaxKind.SpreadElement */)
1554
+ addAlternatives(item, alternatives, true);
1555
+ }
1556
+ else
1557
+ addArrayElements(array, alternatives);
1558
+ }
1559
+ }
1560
+ else {
1561
+ const property = element.propertyName ?? element.name;
1562
+ const propertyName = property.kind === 79 /* SyntaxKind.Identifier */ ? getText(property) : undefined;
1563
+ if (propertyName === undefined)
1564
+ continue;
1565
+ for (const e of elements) {
1566
+ if (e.kind !== 211 /* SyntaxKind.ObjectLiteralExpression */)
1567
+ continue;
1568
+ for (const member of e.properties.nodes)
1569
+ if (member.kind === 303 /* SyntaxKind.PropertyAssignment */ && staticPropertyName(member) === propertyName)
1570
+ addAlternatives(member.initializer, alternatives, true);
1571
+ }
1572
+ }
1573
+ if (alternatives.length !== 0)
1574
+ result.push(alternatives);
1575
+ }
1576
+ return result;
1577
+ }
1578
+ /** The name of an object literal member with a literal name. */
1579
+ function staticPropertyName(member) {
1580
+ switch (member.kind) {
1581
+ case 303 /* SyntaxKind.PropertyAssignment */:
1582
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
1583
+ case 175 /* SyntaxKind.MethodDeclaration */:
1584
+ case 178 /* SyntaxKind.GetAccessor */:
1585
+ case 179 /* SyntaxKind.SetAccessor */:
1586
+ break;
1587
+ default:
1588
+ return undefined;
1589
+ }
1590
+ const name = getName(member);
1591
+ switch (name.kind) {
1592
+ case 79 /* SyntaxKind.Identifier */:
1593
+ case 10 /* SyntaxKind.StringLiteral */:
1594
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
1595
+ return getText(name);
1596
+ case 8 /* SyntaxKind.NumericLiteral */:
1597
+ return String(Number(getText(name)));
1598
+ }
1599
+ return undefined;
1600
+ }
1601
+ function getPropertiesOfContext(c, context) {
1602
+ if (context.resolvedProperties === undefined) {
1603
+ const names = new Map();
1604
+ for (const t of getSiblingsOfContext(c, context))
1605
+ if ((t.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0 &&
1606
+ (t.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
1607
+ (t.objectFlags & 4194304 /* ObjectFlags.ContainsSpread */) === 0)
1608
+ for (const prop of getPropertiesOfType(c, t))
1609
+ names.set(prop.name, prop);
1610
+ context.resolvedProperties = [...names.values()];
1611
+ }
1612
+ return context.resolvedProperties;
1613
+ }
1614
+ function getSiblingsOfContext(c, context) {
1615
+ if (context.siblings === undefined) {
1616
+ const siblings = [];
1617
+ for (const t of getSiblingsOfContext(c, context.parent))
1618
+ if ((t.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0 && (t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
1619
+ const prop = getPropertyOfObjectType(c, t, context.propertyName);
1620
+ if (prop !== undefined) {
1621
+ const propType = getTypeOfSymbol(c, prop);
1622
+ if ((propType.flags & 134217728 /* TypeFlags.Union */) !== 0)
1623
+ for (const u of typesOf(propType))
1624
+ siblings.push(u);
1625
+ else
1626
+ siblings.push(propType);
1627
+ }
1628
+ }
1629
+ context.siblings = siblings;
1630
+ }
1631
+ return context.siblings;
1632
+ }
1633
+ // ---- Optionality
1634
+ export function addOptionality(c, t, isProperty, isOptional) {
1635
+ return c.strictNullChecks && isOptional ? getOptionalType(c, t, isProperty) : t;
1636
+ }
1637
+ export function getOptionalType(c, t, isProperty) {
1638
+ const missingOrUndefined = isProperty ? c.undefinedOrMissingType : c.undefinedType;
1639
+ if (t === missingOrUndefined || ((t.flags & 134217728 /* TypeFlags.Union */) !== 0 && typesOf(t)[0] === missingOrUndefined))
1640
+ return t;
1641
+ const key = cachedTypeKey(isProperty ? 17 /* CachedTypeKind.OptionalProperty */ : 16 /* CachedTypeKind.Optional */, t.id);
1642
+ let result = c.cachedTypesById.get(key);
1643
+ if (result === undefined) {
1644
+ result = getUnionType(c, [t, missingOrUndefined]);
1645
+ c.cachedTypesById.set(key, result);
1646
+ }
1647
+ return result;
1648
+ }
1649
+ export function addOptionalTypeMarker(c, t) {
1650
+ return c.strictNullChecks ? getUnionType(c, [t, c.optionalType]) : t;
1651
+ }
1652
+ export function removeOptionalTypeMarker(c, t) {
1653
+ return c.strictNullChecks ? removeType(c, t, c.optionalType) : t;
1654
+ }
1655
+ export function removeMissingType(c, t, isOptional) {
1656
+ return c.exactOptionalPropertyTypes && isOptional ? removeType(c, t, c.missingType) : t;
1657
+ }
1658
+ export function removeMissingOrUndefinedType(c, t) {
1659
+ return c.exactOptionalPropertyTypes ? removeType(c, t, c.missingType) : getTypeWithFacts(c, t, 524288 /* TypeFacts.NEUndefined */);
1660
+ }
1661
+ export function getNullableType(c, t, flags) {
1662
+ const missing = flags & ~t.flags & (4 /* TypeFlags.Undefined */ | 8 /* TypeFlags.Null */);
1663
+ if (missing === 0)
1664
+ return t;
1665
+ if (missing === 4 /* TypeFlags.Undefined */)
1666
+ return getUnionType(c, [t, c.undefinedType]);
1667
+ if (missing === 8 /* TypeFlags.Null */)
1668
+ return getUnionType(c, [t, c.nullType]);
1669
+ return getUnionType(c, [t, c.undefinedType, c.nullType]);
1670
+ }
1671
+ // ---- Readonly
1672
+ export function isReadonlySymbol(c, symbol) {
1673
+ // Readonly properties, const variables, getters without setters and enum members.
1674
+ return ((symbol.checkFlags & 8 /* CheckFlags.Readonly */) !== 0 ||
1675
+ ((symbol.flags & 4 /* SymbolFlags.Property */) !== 0 &&
1676
+ (getDeclarationModifierFlags(c, symbol) & 8 /* ModifierFlags.Readonly */) !== 0) ||
1677
+ ((symbol.flags & 3 /* SymbolFlags.Variable */) !== 0 &&
1678
+ (getDeclarationNodeFlagsFromSymbol(symbol) & 6 /* NodeFlags.Constant */) !== 0) ||
1679
+ ((symbol.flags & 98304 /* SymbolFlags.Accessor */) !== 0 && (symbol.flags & 65536 /* SymbolFlags.SetAccessor */) === 0) ||
1680
+ (symbol.flags & 8 /* SymbolFlags.EnumMember */) !== 0 ||
1681
+ someReadonlyAssignmentDeclaration(c, symbol.declarations));
1682
+ }
1683
+ function someReadonlyAssignmentDeclaration(c, declarations) {
1684
+ for (const d of declarations)
1685
+ if (isReadonlyAssignmentDeclaration(c, d))
1686
+ return true;
1687
+ return false;
1688
+ }
1689
+ /** An `Object.defineProperty` call with a value and no `writable: true`, or without a setter. */
1690
+ function isReadonlyAssignmentDeclaration(c, node) {
1691
+ if (node.kind !== 214 /* SyntaxKind.CallExpression */)
1692
+ return false;
1693
+ const args = getArguments(node);
1694
+ if (args === undefined || args.nodes.length < 3)
1695
+ return false;
1696
+ const descriptorType = checkExpressionCached(c, args.nodes[2]);
1697
+ if (getTypeOfPropertyOfType(c, descriptorType, 'value') !== undefined) {
1698
+ const writable = getPropertyOfType(c, descriptorType, 'writable');
1699
+ if (writable === undefined)
1700
+ return true;
1701
+ const declaration = writable.valueDeclaration;
1702
+ const writableType = declaration !== undefined && declaration.kind === 303 /* SyntaxKind.PropertyAssignment */
1703
+ ? checkExpression(c, getInitializer(declaration))
1704
+ : getTypeOfSymbol(c, writable);
1705
+ return writableType === c.falseType || writableType === c.regularFalseType;
1706
+ }
1707
+ return getTypeOfPropertyOfType(c, descriptorType, 'set') === undefined;
1708
+ }
1709
+ import { getDeclarationModifierFlagsFromSymbol, getPropertyOfType, getTypeOfPropertyOfType, } from './checker-members.js';
1710
+ import { checkExpression } from './checker-expressions.js';
1711
+ import { getParameterTypeOfFullSignature } from './checker-jsdoc.js';
1712
+ import { isFunctionLike, isFunctionLikeDeclarationKind, isInJSFile } from './ast-utilities.js';
1713
+ import { isEmptyArrayLiteralType } from './relations.js';
1714
+ import { isCheckJsEnabledForFile } from './program-utilities.js';
1715
+ function getDeclarationModifierFlags(c, symbol) {
1716
+ return getDeclarationModifierFlagsFromSymbol(c, symbol, false);
1717
+ }
1718
+ function getDeclarationNodeFlagsFromSymbol(symbol) {
1719
+ return symbol.valueDeclaration !== undefined ? getCombinedNodeFlags(symbol.valueDeclaration) : 0;
1720
+ }
1721
+ // ---- Accessors
1722
+ export function getAnnotatedAccessorTypeNode(accessor) {
1723
+ if (accessor === undefined)
1724
+ return undefined;
1725
+ if (accessor.kind === 178 /* SyntaxKind.GetAccessor */ || accessor.kind === 173 /* SyntaxKind.PropertyDeclaration */)
1726
+ return getType(accessor);
1727
+ if (accessor.kind === 179 /* SyntaxKind.SetAccessor */) {
1728
+ const params = getParameters(accessor)?.nodes ?? [];
1729
+ if (params.length === 0)
1730
+ return undefined;
1731
+ return getType(params.length === 2 ? params[1] : params[0]);
1732
+ }
1733
+ return undefined;
1734
+ }
1735
+ function getAnnotatedAccessorType(c, accessor) {
1736
+ const node = getAnnotatedAccessorTypeNode(accessor);
1737
+ return node !== undefined ? getTypeFromTypeNode(c, node) : undefined;
1738
+ }
1739
+ /** The `accessor` property declaration of `symbol`, if any. */
1740
+ function getAutoAccessorDeclaration(symbol) {
1741
+ for (const d of symbol.declarations)
1742
+ if (d.kind === 173 /* SyntaxKind.PropertyDeclaration */ && (getCombinedModifierFlags(d) & 512 /* ModifierFlags.Accessor */) !== 0)
1743
+ return d;
1744
+ return undefined;
1745
+ }
1746
+ function getTypeOfAccessors(c, symbol) {
1747
+ const id = getSymbolId(symbol);
1748
+ const type = c.symbolTypes.get(id);
1749
+ if (type !== undefined)
1750
+ return type;
1751
+ if (!pushTypeResolution(c, symbol, 0 /* TypeSystemPropertyName.Type */))
1752
+ return c.errorType;
1753
+ const getter = symbol.declarations.find((d) => d.kind === 178 /* SyntaxKind.GetAccessor */);
1754
+ const setter = symbol.declarations.find((d) => d.kind === 179 /* SyntaxKind.SetAccessor */);
1755
+ const accessor = getAutoAccessorDeclaration(symbol);
1756
+ // Getter annotation, setter annotation, accessor annotation, then getter body.
1757
+ let t = getAnnotatedAccessorType(c, getter) ?? getAnnotatedAccessorType(c, setter) ?? getAnnotatedAccessorType(c, accessor);
1758
+ if (t === undefined && getter !== undefined && getBody(getter) !== undefined)
1759
+ t = getReturnTypeFromBody(c, getter);
1760
+ if (t === undefined && accessor !== undefined)
1761
+ t = getWidenedTypeForVariableLikeDeclaration(c, accessor, true);
1762
+ if (t === undefined) {
1763
+ if (setter !== undefined && !isPrivateWithinAmbient(setter))
1764
+ c.addErrorOrSuggestion(c.noImplicitAny, createDiagnosticForNode(setter, 1703 /* Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation */, [symbolToString(c, symbol)]));
1765
+ else if (getter !== undefined && !isPrivateWithinAmbient(getter))
1766
+ c.addErrorOrSuggestion(c.noImplicitAny, createDiagnosticForNode(getter, 1704 /* Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation */, [symbolToString(c, symbol)]));
1767
+ t = c.anyType;
1768
+ }
1769
+ if (!popTypeResolution(c)) {
1770
+ if (getAnnotatedAccessorTypeNode(getter) !== undefined)
1771
+ c.error(getter, 662 /* Diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation */, symbolToString(c, symbol));
1772
+ else if (getAnnotatedAccessorTypeNode(setter) !== undefined)
1773
+ c.error(setter, 662 /* Diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation */, symbolToString(c, symbol));
1774
+ else if (getter !== undefined && c.noImplicitAny)
1775
+ c.error(getter, 1694 /* Diagnostics.X_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions */, symbolToString(c, symbol));
1776
+ t = c.anyType;
1777
+ }
1778
+ let cached = c.symbolTypes.get(id);
1779
+ if (cached === undefined) {
1780
+ cached = t;
1781
+ c.symbolTypes.set(id, cached);
1782
+ }
1783
+ return cached;
1784
+ }
1785
+ export function getWriteTypeOfAccessors(c, symbol) {
1786
+ const links = c.symbolLinks(symbol);
1787
+ if (links.writeType !== undefined)
1788
+ return links.writeType;
1789
+ if (!pushTypeResolution(c, symbol, 7 /* TypeSystemPropertyName.WriteType */))
1790
+ return c.errorType;
1791
+ const setter = symbol.declarations.find((d) => d.kind === 179 /* SyntaxKind.SetAccessor */) ?? getAutoAccessorDeclaration(symbol);
1792
+ let writeType = getAnnotatedAccessorType(c, setter);
1793
+ if (!popTypeResolution(c)) {
1794
+ if (getAnnotatedAccessorTypeNode(setter) !== undefined)
1795
+ c.error(setter, 662 /* Diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation */, symbolToString(c, symbol));
1796
+ writeType = c.anyType;
1797
+ }
1798
+ // Without a setter annotation, the write type is the read type.
1799
+ if (links.writeType === undefined)
1800
+ links.writeType = writeType ?? getTypeOfAccessors(c, symbol);
1801
+ return links.writeType;
1802
+ }
1803
+ // ---- Functions, classes, enums, modules and aliases
1804
+ function getTypeOfFuncClassEnumModule(c, symbol) {
1805
+ const id = getSymbolId(symbol);
1806
+ let type = c.symbolTypes.get(id);
1807
+ if (type === undefined) {
1808
+ type = getTypeOfFuncClassEnumModuleWorker(c, symbol);
1809
+ c.symbolTypes.set(id, type);
1810
+ }
1811
+ return type;
1812
+ }
1813
+ function getTypeOfFuncClassEnumModuleWorker(c, symbol) {
1814
+ if ((symbol.flags & 1536 /* SymbolFlags.Module */) !== 0 && isShorthandAmbientModuleSymbol(symbol))
1815
+ return c.anyType;
1816
+ if ((symbol.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
1817
+ symbol.valueDeclaration !== undefined &&
1818
+ symbol.valueDeclaration.kind === 307 /* SyntaxKind.SourceFile */) {
1819
+ const resolvedModule = resolveExternalModuleSymbol(c, symbol, false);
1820
+ if (resolvedModule !== undefined && resolvedModule !== symbol)
1821
+ return getTypeOfSymbol(c, resolvedModule);
1822
+ }
1823
+ const t = newObjectType(c, 16 /* ObjectFlags.Anonymous */, symbol);
1824
+ if ((symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
1825
+ const baseTypeVariable = getBaseTypeVariableOfClass(c, symbol);
1826
+ return baseTypeVariable !== undefined ? getIntersectionType(c, [t, baseTypeVariable]) : t;
1827
+ }
1828
+ if (c.strictNullChecks && (symbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0)
1829
+ return getOptionalType(c, t, true);
1830
+ return t;
1831
+ }
1832
+ function isShorthandAmbientModuleSymbol(symbol) {
1833
+ const d = symbol.valueDeclaration;
1834
+ return d !== undefined && d.kind === 268 /* SyntaxKind.ModuleDeclaration */ && getBody(d) === undefined;
1835
+ }
1836
+ export function getBaseTypeVariableOfClass(c, symbol) {
1837
+ const baseConstructorType = getBaseConstructorTypeOfClass(c, getDeclaredTypeOfClassOrInterface(c, symbol));
1838
+ if ((baseConstructorType.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0)
1839
+ return baseConstructorType;
1840
+ if ((baseConstructorType.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
1841
+ return typesOf(baseConstructorType).find((t) => (t.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0);
1842
+ return undefined;
1843
+ }
1844
+ function getTypeOfEnumMember(c, symbol) {
1845
+ const id = getSymbolId(symbol);
1846
+ let type = c.symbolTypes.get(id);
1847
+ if (type === undefined) {
1848
+ type = getDeclaredTypeOfEnumMember(c, symbol);
1849
+ c.symbolTypes.set(id, type);
1850
+ }
1851
+ return type;
1852
+ }
1853
+ function getTypeOfAlias(c, symbol) {
1854
+ const id = getSymbolId(symbol);
1855
+ const type = c.symbolTypes.get(id);
1856
+ if (type !== undefined)
1857
+ return type;
1858
+ if (!pushTypeResolution(c, symbol, 0 /* TypeSystemPropertyName.Type */))
1859
+ return c.errorType;
1860
+ const targetSymbol = resolveAlias(c, symbol);
1861
+ const exportSymbol = getTargetOfAliasDeclaration(c, getDeclarationOfAliasSymbol(symbol));
1862
+ // Only values have types.
1863
+ if (c.symbolTypes.get(id) === undefined)
1864
+ c.symbolTypes.set(id, (getSymbolFlags(c, targetSymbol) & 111551 /* SymbolFlags.Value */) !== 0 ? getTypeOfSymbol(c, targetSymbol) : c.errorType);
1865
+ if (!popTypeResolution(c)) {
1866
+ reportCircularityError(c, exportSymbol ?? symbol);
1867
+ if (c.symbolTypes.get(id) === undefined)
1868
+ c.symbolTypes.set(id, c.errorType);
1869
+ }
1870
+ return c.symbolTypes.get(id);
1871
+ }
1872
+ function getTypeOfPrototypeProperty(c, prototype) {
1873
+ // Every class has a `prototype` of its instance type with `any` type arguments.
1874
+ const classType = getDeclaredTypeOfSymbol(c, getParentOfSymbol(c, prototype));
1875
+ const typeParameters = classType.typeParameters();
1876
+ return typeParameters.length !== 0
1877
+ ? createTypeReference(c, classType, typeParameters.map(() => c.anyType))
1878
+ : classType;
1879
+ }
1880
+ export { getDeclarationOfAliasSymbol, filterType, hasStaticModifier };
1881
+ /** `Extract<t, string>`, or string without the global `Extract`. */
1882
+ export function getExtractStringType(c, t) {
1883
+ const extract = getGlobalTypeAliasSymbol(c, 'Extract', 2, true);
1884
+ return extract !== undefined ? getTypeAliasInstantiation(c, extract, [t, c.stringType], undefined) : c.stringType;
1885
+ }