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,1831 @@
1
+ // Expression checking: types of expressions and the errors they produce.
2
+ import {
3
+ checkMetaProperty,
4
+ getIsolatedModulesLikeFlagName,
5
+ isValidTypeOnlyAliasUseSite,
6
+ markIdentifierAliasReferencedInExpression,
7
+ } from './checker-modules.js';
8
+ import { checkDeprecatedIdentifier } from './checker-deprecation.js';
9
+ import { isWriteOnlyAccess } from './checker-unused.js';
10
+ import {
11
+ type ArrayLiteralExpression,
12
+ type CallExpression,
13
+ BinaryExpression,
14
+ type ComputedPropertyName,
15
+ type ConditionalExpression,
16
+ type ElementAccessExpression,
17
+ type Identifier,
18
+ type Node,
19
+ type PrefixUnaryExpression,
20
+ type PostfixUnaryExpression,
21
+ type PropertyAccessExpression,
22
+ type QualifiedName,
23
+ type SpreadElement,
24
+ type TemplateExpression,
25
+ type TemplateSpan,
26
+ type TypeReferenceNode,
27
+ getExpression,
28
+ getInitializer,
29
+ getName,
30
+ getText,
31
+ SourceFile,
32
+ ModifierFlags,
33
+ NodeFlags,
34
+ PropertyDeclaration,
35
+ VariableDeclaration,
36
+ ForInOrOfStatement,
37
+ VariableDeclarationList,
38
+ TypeQueryNode,
39
+ type ImportEqualsDeclaration,
40
+ getTagName,
41
+ getType,
42
+ } from './ast.js';
43
+ import {
44
+ getThisContainer,
45
+ isEntityNameExpression,
46
+ isStatic,
47
+ skipParentheses,
48
+ isClassLike,
49
+ getNameOfDeclaration,
50
+ getRootDeclaration,
51
+ hasSyntacticModifier,
52
+ isFunctionExpressionOrArrowFunction,
53
+ isObjectLiteralOrClassExpressionMethodOrAccessor,
54
+ isPartOfTypeQuery,
55
+ isOptionalChain,
56
+ isAssignmentTarget,
57
+ getSourceFileOfNode,
58
+ } from './binder-utilities.js';
59
+ import { shouldCheckErasableSyntax } from './checker-declarations.js';
60
+ import { skipTrivia } from './scanner.js';
61
+ import { Diagnostic, Diagnostics } from './diagnostics.js';
62
+ import { type Symbol, SymbolFlags } from './symbol.js';
63
+ import { SyntaxKind } from './syntax-kind.js';
64
+ import { type Checker } from './checker.js';
65
+ import {
66
+ checkSuperExpression,
67
+ checkThisBeforeSuper,
68
+ checkThisInStaticClassFieldInitializerInDecoratedClass,
69
+ } from './checker-super.js';
70
+ import {
71
+ CachedTypeKind,
72
+ cachedTypeKey,
73
+ AccessFlags,
74
+ NodeCheckFlags,
75
+ CheckMode,
76
+ ObjectFlags,
77
+ SignatureKind,
78
+ type Type,
79
+ TypeFlags,
80
+ UnionType,
81
+ TypeParameter,
82
+ type MappedType,
83
+ type TypeReference,
84
+ IndexFlags,
85
+ type IndexedAccessType,
86
+ type SubstitutionType,
87
+ } from './checker-types.js';
88
+ import {
89
+ createTupleTypeEx,
90
+ getBigIntLiteralType,
91
+ getFreshTypeOfLiteralType,
92
+ getNumberLiteralType,
93
+ getRegularTypeOfLiteralType,
94
+ getStringLiteralType,
95
+ getUnionTypeEx,
96
+ getWidenedLiteralType,
97
+ getWidenedUniqueESSymbolType,
98
+ isErrorType,
99
+ isTupleType,
100
+ someType,
101
+ typesOf,
102
+ UnionReduction,
103
+ getBaseTypeOfLiteralType,
104
+ cloneTypeReference,
105
+ createArrayTypeEx,
106
+ everyType,
107
+ getTemplateLiteralType,
108
+ isMutableArrayOrTuple,
109
+ } from './checker-type-factory.js';
110
+ import { ElementFlags, TupleElementInfo } from './checker-types.js';
111
+ import {
112
+ getBaseConstraintOfType,
113
+ getPropertyOfType,
114
+ getIndexInfoOfType,
115
+ getIndexInfosOfType,
116
+ getIndexTypeOfType,
117
+ getTypeOfPropertyOfType,
118
+ isArrayLikeType,
119
+ getBaseConstraintOrType,
120
+ isApplicableIndexType,
121
+ getDeclarationModifierFlagsFromSymbol,
122
+ getApparentType,
123
+ mapToBaseConstraintOrType,
124
+ } from './checker-members.js';
125
+ import {
126
+ getExportSymbolOfValueSymbolIfExported,
127
+ getMergedSymbol,
128
+ getSymbolOfDeclaration,
129
+ resolveEntityName,
130
+ resolveName,
131
+ getFirstIdentifier,
132
+ getCannotFindNameDiagnosticForName,
133
+ getDeclarationOfAliasSymbol,
134
+ TypeSystemPropertyName,
135
+ popTypeResolution,
136
+ pushTypeResolution,
137
+ reportCircularityError,
138
+ } from './checker-symbols.js';
139
+ import {
140
+ getTypeOfSymbol,
141
+ getWidenedType,
142
+ isReadonlySymbol,
143
+ getOptionalType,
144
+ removeMissingType,
145
+ addOptionality,
146
+ } from './checker-symbol-types.js';
147
+ import { getDeclaredTypeOfClassOrInterface } from './checker-declared-types.js';
148
+ import { getTypeFromTypeNode } from './checker-type-nodes.js';
149
+ import {
150
+ isGenericObjectType,
151
+ getIndexedAccessTypeOrUndefinedEx,
152
+ getHomomorphicTypeVariable,
153
+ isGenericIndexType,
154
+ isGenericMappedType,
155
+ isGenericType,
156
+ getMappedTypeNameTypeKind,
157
+ MappedTypeNameTypeKind,
158
+ getIndexForMappedType,
159
+ getIndexTypeEx,
160
+ getMappedTypeModifiers,
161
+ MappedTypeModifiers,
162
+ getPropertyNameFromIndex,
163
+ isNoInferType,
164
+ } from './checker-type-operators.js';
165
+ import { TypeFacts, getTypeFacts, getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-flow.js';
166
+ import { checkTypeComparableTo, isTypeAssignableTo, isTypeComparableTo } from './relations.js';
167
+ import { isTypeAssignableToKindEx as isTypeAssignableToKind } from './checker-type-operators.js';
168
+ import { typeToString, symbolToString } from './type-printer.js';
169
+ import { isTypeUsableAsPropertyName, getPropertyNameFromType, maybeTypeOfKind } from './checker-utilities.js';
170
+ import {
171
+ getApparentTypeOfContextualType,
172
+ getContextualType,
173
+ getContextualTypeEx,
174
+ getContextualSignatureForFunctionLikeDeclaration,
175
+ } from './checker-contextual.js';
176
+ import {
177
+ checkCallExpression,
178
+ checkExpressionWithTypeArguments,
179
+ checkNewExpression,
180
+ checkTaggedTemplateExpression,
181
+ getOptionalExpressionType,
182
+ instantiateTypeWithSingleGenericCallSignature,
183
+ isSymbolOrSymbolForCall,
184
+ propagateOptionalTypeMarker,
185
+ } from './checker-calls.js';
186
+ import {
187
+ checkAwaitExpression,
188
+ checkFunctionExpressionOrObjectLiteralMethod,
189
+ checkYieldExpression,
190
+ } from './checker-functions.js';
191
+ import {
192
+ IterationUse,
193
+ checkIteratedTypeOrElementType,
194
+ getAwaitedType,
195
+ getIteratedTypeOrElementType,
196
+ } from './checker-iteration.js';
197
+ import { checkClassExpression } from './checker-classes.js';
198
+ import { padParameterInitializerType } from './checker-destructuring.js';
199
+ import { checkNodeDeferred, checkTypeNodeIfPresent } from './checker-source-file.js';
200
+ import { isInPropertyInitializerOrClassStaticBlock } from './checker-declaration-order.js';
201
+ import { checkObjectLiteral } from './checker-object-literals.js';
202
+ import { EvaluatedKind, evaluate } from './checker-evaluator.js';
203
+ import {
204
+ checkPrivateIdentifierExpression,
205
+ checkPropertyAccessExpressionOrQualifiedName,
206
+ isMethodAccessForCall,
207
+ } from './checker-property-access.js';
208
+ import {
209
+ checkBinaryExpression,
210
+ checkConditionalExpression,
211
+ checkDeleteExpression,
212
+ checkPostfixUnaryExpression,
213
+ checkPrefixUnaryExpression,
214
+ isTypeAssertion,
215
+ } from './checker-operators.js';
216
+ import { checkJsx } from './checker-jsx.js';
217
+ import { getRegularTypeOfObjectLiteral } from './checker-literals.js';
218
+ import {
219
+ getReturnTypeOfSignature,
220
+ getSignatureFromDeclaration,
221
+ getSingleSignature,
222
+ getThisTypeOfSignature,
223
+ } from './checker-signatures.js';
224
+ import { isFunctionLike, isImportCall, isInJSFile, isRequireCall } from './ast-utilities.js';
225
+ import { isLiteralKind } from './printer/utilities.js';
226
+ import {
227
+ AssignmentKind,
228
+ convertAutoToAny,
229
+ isEvolvingArrayOperationTarget,
230
+ getAssignmentTargetKind,
231
+ getControlFlowContainer,
232
+ isConstantVariable,
233
+ isInCompoundLikeAssignment,
234
+ isMutableLocalVariableDeclaration,
235
+ isParameterOrMutableLocalVariable,
236
+ isPastLastAssignment,
237
+ isSymbolAssignedDefinitely,
238
+ getFlowTypeOfReference,
239
+ getNarrowedTypeOfSymbol,
240
+ } from './checker-narrowing.js';
241
+ import { getFlowTypeOfAutoTypedProperty, getThisTypeOfAssignedFunction } from './checker-javascript.js';
242
+ import { checkExpressionWithContextualType, getThisTypeOfObjectLiteralMember } from './checker-contextual.js';
243
+
244
+ import {
245
+ ContextFlags,
246
+ getInferenceContext,
247
+ instantiateContextualType,
248
+ popContextualType,
249
+ pushCachedContextualType,
250
+ } from './checker-contextual.js';
251
+ import { addIntraExpressionInferenceSite, isConstTypeVariable } from './checker-inference.js';
252
+ import { isContextSensitiveFunctionOrObjectLiteralMethod } from './checker-contextual.js';
253
+ import { checkTypeRelatedToAndOptionallyElaborate } from './checker-elaboration.js';
254
+ import { isContextSensitive } from './checker-functions.js';
255
+ import { getSignatureOfFullSignatureType } from './checker-jsdoc.js';
256
+ export {
257
+ getContextuallyTypedParameterType,
258
+ isContextSensitiveFunctionOrObjectLiteralMethod,
259
+ } from './checker-contextual.js';
260
+
261
+ // ---- Entry points
262
+
263
+ export function checkExpression(c: Checker, node: Node): Type {
264
+ return checkExpressionEx(c, node, CheckMode.Normal);
265
+ }
266
+
267
+ export function checkExpressionEx(c: Checker, node: Node, checkMode: CheckMode): Type {
268
+ const saveCurrentNode = c.currentNode;
269
+ c.currentNode = node;
270
+ c.instantiationCount = 0;
271
+ const t = instantiateTypeWithSingleGenericCallSignature(
272
+ c,
273
+ node,
274
+ checkExpressionWorker(c, node, checkMode),
275
+ checkMode,
276
+ );
277
+ if (isConstEnumObjectTypeLocal(t)) checkConstEnumAccess(c, node, t);
278
+ c.currentNode = saveCurrentNode;
279
+ return t;
280
+ }
281
+
282
+ /**
283
+ * A const enum object can only be accessed, imported, exported or queried. Under isolatedModules, an
284
+ * ambient one can't be used at all outside types.
285
+ */
286
+ function checkConstEnumAccess(c: Checker, node: Node, t: Type): void {
287
+ const parent = node.parent!;
288
+ const ok =
289
+ ((parent.kind === SyntaxKind.PropertyAccessExpression || parent.kind === SyntaxKind.ElementAccessExpression) &&
290
+ getExpression(parent) === node) ||
291
+ ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) &&
292
+ isInRightSideOfImportOrExportAssignment(node)) ||
293
+ (parent.kind === SyntaxKind.TypeQuery && (parent as TypeQueryNode).exprName === node) ||
294
+ parent.kind === SyntaxKind.ExportSpecifier;
295
+ if (!ok)
296
+ c.error(
297
+ node,
298
+ Diagnostics.X_const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query,
299
+ );
300
+ // Under verbatimModuleSyntax, only uses that don't resolve to an import are checked here; imports of
301
+ // ambient const enums are checked with the alias.
302
+ if (
303
+ c.compilerOptions.isolatedModules === true ||
304
+ (c.compilerOptions.verbatimModuleSyntax === true &&
305
+ ok &&
306
+ resolveName(c, node, getText(getFirstIdentifier(node)), SymbolFlags.Alias, undefined, false, true) === undefined)
307
+ ) {
308
+ const constEnumDeclaration = t.symbol!.valueDeclaration!;
309
+ if ((constEnumDeclaration.flags & NodeFlags.Ambient) !== 0 && !isValidTypeOnlyAliasUseSite(node))
310
+ c.error(node, Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, getIsolatedModulesLikeFlagName(c));
311
+ }
312
+ }
313
+
314
+ function isInRightSideOfImportOrExportAssignment(name: Node): boolean {
315
+ let node = name;
316
+ while (node.parent!.kind === SyntaxKind.QualifiedName) node = node.parent!;
317
+ const parent = node.parent!;
318
+ return (
319
+ (parent.kind === SyntaxKind.ImportEqualsDeclaration &&
320
+ (parent as ImportEqualsDeclaration).moduleReference === node) ||
321
+ (parent.kind === SyntaxKind.ExportAssignment && getExpression(parent) === node)
322
+ );
323
+ }
324
+
325
+ /** The type of `node`, computed once. */
326
+ export function checkExpressionCached(c: Checker, node: Node): Type {
327
+ let type = c.resolvedTypes.get(node.id);
328
+ if (type === undefined) {
329
+ // A type that is cached is computed without the control flow analysis in progress, whose variables may
330
+ // have transient types: loops being analyzed start over.
331
+ const saveFlowLoopStack = c.flowLoopStack;
332
+ const saveFlowTypeCache = c.flowTypeCache;
333
+ if (saveFlowLoopStack.length !== 0) c.flowLoopStack = [];
334
+ c.flowTypeCache = undefined;
335
+ type = checkExpression(c, node);
336
+ c.resolvedTypes.set(node.id, type);
337
+ c.flowTypeCache = saveFlowTypeCache;
338
+ c.flowLoopStack = saveFlowLoopStack;
339
+ }
340
+ return type;
341
+ }
342
+
343
+ /** The type of an expression, cached when computing it needed flow analysis; may skip some diagnostics. */
344
+ export function getTypeOfExpression(c: Checker, node: Node): Type {
345
+ const quickType = getQuickTypeOfExpression(c, node);
346
+ if (quickType !== undefined) return quickType;
347
+ const cachedType = c.flowTypeCache?.get(node);
348
+ if (cachedType !== undefined) return cachedType;
349
+ const startInvocationCount = c.flowInvocationCount;
350
+ const t = checkExpressionEx(c, node, CheckMode.TypeOnly);
351
+ if (c.flowInvocationCount !== startInvocationCount) {
352
+ if (c.flowTypeCache === undefined) c.flowTypeCache = new Map<Node, Type>();
353
+ c.flowTypeCache.set(node, t);
354
+ }
355
+ return t;
356
+ }
357
+
358
+ /** The type of an initializer in a position where literals widen unless the context wants them. */
359
+ export function checkExpressionForMutableLocation(c: Checker, node: Node): Type {
360
+ return checkExpressionForMutableLocationEx(c, node, CheckMode.Normal);
361
+ }
362
+
363
+ export function checkExpressionForMutableLocationEx(c: Checker, node: Node, checkMode: CheckMode): Type {
364
+ const t = checkExpressionEx(c, node, checkMode);
365
+ if (isConstContext(c, node)) return getRegularTypeOfLiteralType(c, t);
366
+ // An asserted type is kept as written.
367
+ if (isTypeAssertion(node)) return t;
368
+ return getWidenedLiteralLikeTypeForContextualType(
369
+ c,
370
+ t,
371
+ instantiateContextualType(c, getContextualType(c, node), node, ContextFlags.None),
372
+ );
373
+ }
374
+
375
+ export function checkDeclarationInitializer(
376
+ c: Checker,
377
+ declaration: Node,
378
+ checkMode: CheckMode = CheckMode.Normal,
379
+ contextualType?: Type,
380
+ ): Type {
381
+ const initializer = getInitializer(declaration)!;
382
+ const t =
383
+ getQuickTypeOfExpression(c, initializer) ??
384
+ (contextualType !== undefined
385
+ ? checkExpressionWithContextualType(c, initializer, contextualType, undefined, checkMode)
386
+ : checkMode === CheckMode.Normal
387
+ ? checkExpressionCached(c, initializer)
388
+ : checkExpressionEx(c, initializer, checkMode));
389
+ return padParameterInitializerType(c, declaration, t);
390
+ }
391
+
392
+ /**
393
+ * The type of an expression whose type doesn't need its arguments checked: a call or `new` of a single
394
+ * non-generic signature, an assertion, or a literal.
395
+ */
396
+ function getQuickTypeOfExpression(c: Checker, node: Node): Type | undefined {
397
+ const expr = skipParentheses(node);
398
+ switch (expr.kind) {
399
+ case SyntaxKind.AwaitExpression: {
400
+ const t = getQuickTypeOfExpression(c, getExpression(expr)!);
401
+ return t !== undefined ? getAwaitedType(c, t) : undefined;
402
+ }
403
+ case SyntaxKind.CallExpression: {
404
+ const call = expr as CallExpression;
405
+ if (
406
+ call.expression.kind === SyntaxKind.SuperKeyword ||
407
+ isRequireCall(call, true) ||
408
+ isSymbolOrSymbolForCall(c, call) ||
409
+ isImportCall(call)
410
+ )
411
+ return undefined;
412
+ if (isOptionalChain(call)) {
413
+ const funcType = checkExpression(c, call.expression);
414
+ const nonOptionalType = getOptionalExpressionType(c, funcType, call.expression);
415
+ const returnType = getReturnTypeOfSingleNonGenericSignature(c, funcType, SignatureKind.Call);
416
+ return returnType !== undefined
417
+ ? propagateOptionalTypeMarker(c, returnType, call, nonOptionalType !== funcType)
418
+ : undefined;
419
+ }
420
+ return getReturnTypeOfSingleNonGenericSignature(
421
+ c,
422
+ checkNonNullExpression(c, call.expression),
423
+ SignatureKind.Call,
424
+ );
425
+ }
426
+ case SyntaxKind.NewExpression:
427
+ return getReturnTypeOfSingleNonGenericSignature(
428
+ c,
429
+ checkNonNullExpression(c, getExpression(expr)!),
430
+ SignatureKind.Construct,
431
+ );
432
+ case SyntaxKind.AsExpression:
433
+ case SyntaxKind.TypeAssertionExpression: {
434
+ const typeNode = getType(expr)!;
435
+ return isConstTypeReference(typeNode) ? undefined : getTypeFromTypeNode(c, typeNode);
436
+ }
437
+ }
438
+ if (isLiteralKind(node.kind) || node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword)
439
+ return checkExpression(c, node);
440
+ return undefined;
441
+ }
442
+
443
+ function getReturnTypeOfSingleNonGenericSignature(c: Checker, funcType: Type, kind: SignatureKind): Type | undefined {
444
+ const signature = getSingleSignature(c, funcType, kind, true);
445
+ return signature !== undefined && signature.typeParameters.length === 0
446
+ ? getReturnTypeOfSignature(c, signature)
447
+ : undefined;
448
+ }
449
+
450
+ export function checkComputedPropertyName(c: Checker, node: Node): Type {
451
+ const nodeId = (node as ComputedPropertyName).expression.id;
452
+ if (c.resolvedTypes.get(nodeId) === undefined) {
453
+ const expression = (node as ComputedPropertyName).expression;
454
+ const container = node.parent!.parent!;
455
+ // `[x in y]` in a type member is a mapped type written in the wrong place, reported by the parser.
456
+ if (
457
+ (container.kind === SyntaxKind.TypeLiteral ||
458
+ isClassLike(container) ||
459
+ container.kind === SyntaxKind.InterfaceDeclaration) &&
460
+ expression.kind === SyntaxKind.BinaryExpression &&
461
+ (expression as BinaryExpression).operatorToken.kind === SyntaxKind.InKeyword &&
462
+ node.parent!.kind !== SyntaxKind.GetAccessor &&
463
+ node.parent!.kind !== SyntaxKind.SetAccessor
464
+ ) {
465
+ c.resolvedTypes.set(nodeId, c.errorType);
466
+ return c.resolvedTypes.get(nodeId)!;
467
+ }
468
+ const t = checkExpression(c, expression);
469
+ c.resolvedTypes.set(nodeId, t);
470
+ // Allows string, number, symbol and any, as well as enums, unknown and unions of them.
471
+ if (
472
+ (t.flags & TypeFlags.Nullable) !== 0 ||
473
+ (!isTypeAssignableToKind(c, t, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbolLike, false) &&
474
+ !isTypeAssignableTo(c, t, c.stringNumberSymbolType))
475
+ )
476
+ c.error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any);
477
+ }
478
+ return c.resolvedTypes.get(nodeId)!;
479
+ }
480
+
481
+ /** A parameter's declared type without `undefined` when its initializer can't be `undefined`. */
482
+ function removeOptionalityFromDeclaredType(c: Checker, declaredType: Type, declaration: Node): Type {
483
+ const removeUndefined =
484
+ c.strictNullChecks &&
485
+ declaration.kind === SyntaxKind.Parameter &&
486
+ getInitializer(declaration) !== undefined &&
487
+ hasTypeFacts(c, declaredType, TypeFacts.IsUndefined) &&
488
+ !parameterInitializerContainsUndefined(c, declaration);
489
+ return removeUndefined ? getTypeWithFacts(c, declaredType, TypeFacts.NEUndefined) : declaredType;
490
+ }
491
+
492
+ function parameterInitializerContainsUndefined(c: Checker, declaration: Node): boolean {
493
+ const links = c.nodeLinks(declaration);
494
+ if ((links.flags & NodeCheckFlags.InitializerIsUndefinedComputed) === 0) {
495
+ if (!pushTypeResolution(c, declaration, TypeSystemPropertyName.InitializerIsUndefined)) {
496
+ reportCircularityError(c, getSymbolOfDeclaration(c, declaration)!);
497
+ return true;
498
+ }
499
+ const containsUndefined = hasTypeFacts(c, checkDeclarationInitializer(c, declaration), TypeFacts.IsUndefined);
500
+ if (!popTypeResolution(c)) {
501
+ reportCircularityError(c, getSymbolOfDeclaration(c, declaration)!);
502
+ return true;
503
+ }
504
+ if ((links.flags & NodeCheckFlags.InitializerIsUndefinedComputed) === 0)
505
+ links.flags |=
506
+ NodeCheckFlags.InitializerIsUndefinedComputed | (containsUndefined ? NodeCheckFlags.InitializerIsUndefined : 0);
507
+ }
508
+ return (links.flags & NodeCheckFlags.InitializerIsUndefined) !== 0;
509
+ }
510
+
511
+ /** Whether `node` is the operand of a spread in an object destructuring assignment, as in `({ ...x } = obj)`. */
512
+ function isSpreadDestructuringAssignmentTarget(node: Node): boolean {
513
+ const parent = node.parent!;
514
+ if (parent.kind !== SyntaxKind.SpreadAssignment || parent.parent === undefined) return false;
515
+ const pattern = parent.parent;
516
+ const grandparent = pattern.parent!;
517
+ return (
518
+ (grandparent.kind === SyntaxKind.BinaryExpression && (grandparent as BinaryExpression).left === pattern) ||
519
+ (grandparent.kind === SyntaxKind.ForOfStatement && (grandparent as ForInOrOfStatement).initializer === pattern)
520
+ );
521
+ }
522
+
523
+ /** Whether `node` is in a binding element of the same declaration as the binding element `declaration`. */
524
+ function isSameScopedBindingElement(node: Node, declaration: Node): boolean {
525
+ if (declaration.kind !== SyntaxKind.BindingElement) return false;
526
+ let bindingElement = node.parent;
527
+ while (bindingElement !== undefined && bindingElement.kind !== SyntaxKind.BindingElement)
528
+ bindingElement = bindingElement.parent;
529
+ return bindingElement !== undefined && getRootDeclaration(bindingElement) === getRootDeclaration(declaration);
530
+ }
531
+
532
+ /** Whether `node` is the `this` of `typeof this` or `typeof this.x`, which parses as an identifier. */
533
+ export function isThisInTypeQuery(node: Node): boolean {
534
+ if (node.kind !== SyntaxKind.Identifier || getText(node) !== 'this') return false;
535
+ let current = node;
536
+ while (current.parent!.kind === SyntaxKind.QualifiedName && (current.parent as QualifiedName).left === current)
537
+ current = current.parent!;
538
+ return current.parent!.kind === SyntaxKind.TypeQuery;
539
+ }
540
+
541
+ /** The type of the expression in a `typeof` type query. */
542
+ export function checkTypeQueryExpression(c: Checker, node: Node): Type {
543
+ const exprName = (node as TypeQueryNode).exprName;
544
+ if (exprName.kind === SyntaxKind.Identifier) return checkIdentifier(c, exprName as Identifier);
545
+ if (exprName.kind === SyntaxKind.QualifiedName) return checkQualifiedName(c, exprName as QualifiedName);
546
+ if (exprName.kind === SyntaxKind.ThisKeyword) return checkThisExpression(c, exprName);
547
+ return c.errorType;
548
+ }
549
+
550
+ /** The symbol an identifier refers to as a value; reports unresolved names. */
551
+ export function getResolvedSymbol(c: Checker, node: Node): Symbol {
552
+ const cached = c.resolvedSymbols.get(node.id);
553
+ if (cached !== undefined) return cached;
554
+ let symbol = c.unknownSymbol;
555
+ if (getText(node) !== '') {
556
+ const text = getText(node);
557
+ const found = resolveName(
558
+ c,
559
+ node,
560
+ text,
561
+ SymbolFlags.Value | SymbolFlags.ExportValue,
562
+ getCannotFindNameDiagnosticForName(c, node),
563
+ !isWriteOnlyAccess(node),
564
+ false,
565
+ );
566
+ if (found !== undefined) symbol = found;
567
+ }
568
+ c.resolvedSymbols.set(node.id, symbol);
569
+ return symbol;
570
+ }
571
+
572
+ // ---- Dispatch
573
+
574
+ function checkExpressionWorker(c: Checker, node: Node, checkMode: CheckMode): Type {
575
+ switch (node.kind) {
576
+ case SyntaxKind.Identifier:
577
+ return checkIdentifier(c, node as Identifier, checkMode);
578
+ case SyntaxKind.PrivateIdentifier:
579
+ return checkPrivateIdentifierExpression(c, node);
580
+ case SyntaxKind.ThisKeyword:
581
+ return checkThisExpression(c, node);
582
+ case SyntaxKind.SuperKeyword:
583
+ return checkSuperExpression(c, node);
584
+ case SyntaxKind.NullKeyword:
585
+ return c.nullWideningType;
586
+ case SyntaxKind.TrueKeyword:
587
+ return c.trueType;
588
+ case SyntaxKind.FalseKeyword:
589
+ return c.falseType;
590
+ case SyntaxKind.StringLiteral:
591
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
592
+ return getFreshTypeOfLiteralType(c, getStringLiteralType(c, getText(node)));
593
+ case SyntaxKind.NumericLiteral:
594
+ return getFreshTypeOfLiteralType(c, getNumberLiteralType(c, Number(getText(node))));
595
+ case SyntaxKind.BigIntLiteral:
596
+ return getFreshTypeOfLiteralType(c, getBigIntLiteralType(c, parseBigIntText(getText(node))));
597
+ case SyntaxKind.TemplateExpression:
598
+ return checkTemplateExpression(c, node as TemplateExpression);
599
+ case SyntaxKind.RegularExpressionLiteral:
600
+ return c.globalRegExpType;
601
+ case SyntaxKind.ArrayLiteralExpression:
602
+ return checkArrayLiteral(c, node as ArrayLiteralExpression, checkMode);
603
+ case SyntaxKind.ObjectLiteralExpression:
604
+ return checkObjectLiteral(c, node, checkMode);
605
+ case SyntaxKind.PropertyAccessExpression:
606
+ return checkPropertyAccessExpression(c, node as PropertyAccessExpression, false, checkMode);
607
+ case SyntaxKind.QualifiedName:
608
+ return checkQualifiedName(c, node as QualifiedName);
609
+ case SyntaxKind.ElementAccessExpression:
610
+ return checkElementAccessExpression(c, node as ElementAccessExpression, checkMode);
611
+ case SyntaxKind.CallExpression:
612
+ return checkCallExpression(c, node, checkMode);
613
+ case SyntaxKind.NewExpression:
614
+ return checkNewExpression(c, node, checkMode);
615
+ case SyntaxKind.TaggedTemplateExpression:
616
+ return checkTaggedTemplateExpression(c, node, checkMode);
617
+ case SyntaxKind.ParenthesizedExpression:
618
+ return checkExpressionEx(c, getExpression(node)!, checkMode);
619
+ case SyntaxKind.ClassExpression:
620
+ return checkClassExpression(c, node);
621
+ case SyntaxKind.FunctionExpression:
622
+ case SyntaxKind.ArrowFunction:
623
+ return checkFunctionExpressionOrObjectLiteralMethod(c, node, checkMode);
624
+ case SyntaxKind.TypeOfExpression:
625
+ checkExpression(c, getExpression(node)!);
626
+ return c.typeofType;
627
+ case SyntaxKind.TypeAssertionExpression:
628
+ case SyntaxKind.AsExpression:
629
+ return checkAssertion(c, node, checkMode);
630
+ case SyntaxKind.NonNullExpression: {
631
+ const leftType = checkExpressionEx(c, getExpression(node)!, checkMode);
632
+ if ((node.flags & NodeFlags.OptionalChain) === 0) return getNonNullableType(c, leftType);
633
+ // In an optional chain, the chain's undefined stays.
634
+ const nonOptionalType = getOptionalExpressionType(c, leftType, getExpression(node)!);
635
+ return propagateOptionalTypeMarker(c, getNonNullableType(c, nonOptionalType), node, nonOptionalType !== leftType);
636
+ }
637
+ case SyntaxKind.ExpressionWithTypeArguments:
638
+ return checkExpressionWithTypeArguments(c, node);
639
+ case SyntaxKind.SatisfiesExpression:
640
+ return checkSatisfiesExpression(c, node, checkMode);
641
+ case SyntaxKind.MetaProperty:
642
+ return checkMetaProperty(c, node);
643
+ case SyntaxKind.DeleteExpression:
644
+ return checkDeleteExpression(c, node);
645
+ case SyntaxKind.VoidExpression:
646
+ // The operand is checked deferred.
647
+ checkNodeDeferred(c, node);
648
+ return c.undefinedWideningType;
649
+ case SyntaxKind.AwaitExpression:
650
+ return checkAwaitExpression(c, node);
651
+ case SyntaxKind.PrefixUnaryExpression:
652
+ return checkPrefixUnaryExpression(c, node as PrefixUnaryExpression);
653
+ case SyntaxKind.PostfixUnaryExpression:
654
+ return checkPostfixUnaryExpression(c, node as PostfixUnaryExpression);
655
+ case SyntaxKind.BinaryExpression:
656
+ return checkBinaryExpression(c, node as BinaryExpression, checkMode);
657
+ case SyntaxKind.ConditionalExpression:
658
+ return checkConditionalExpression(c, node as ConditionalExpression, checkMode);
659
+ case SyntaxKind.SpreadElement:
660
+ return checkSpreadExpression(c, node as SpreadElement, checkMode);
661
+ case SyntaxKind.OmittedExpression:
662
+ return c.undefinedWideningType;
663
+ case SyntaxKind.YieldExpression:
664
+ return checkYieldExpression(c, node);
665
+ case SyntaxKind.SyntheticExpression:
666
+ return c.anyType;
667
+ case SyntaxKind.JsxExpression:
668
+ case SyntaxKind.JsxElement:
669
+ case SyntaxKind.JsxSelfClosingElement:
670
+ case SyntaxKind.JsxFragment:
671
+ case SyntaxKind.JsxAttributes:
672
+ return checkJsx(c, node, checkMode);
673
+ }
674
+ return c.errorType;
675
+ }
676
+
677
+ export function parseBigIntText(text: string): string {
678
+ let digits = text.endsWith('n') ? text.substring(0, text.length - 1) : text;
679
+ digits = digits.split('_').join('');
680
+ if (digits.length > 2 && digits.charCodeAt(0) === 0x30) {
681
+ const radix = digits.charCodeAt(1) | 0x20;
682
+ if (radix === 0x78 || radix === 0x6f || radix === 0x62) return BigInt(digits).toString();
683
+ }
684
+ let i = 0;
685
+ while (i < digits.length - 1 && digits.charCodeAt(i) === 0x30) i++;
686
+ return digits.substring(i);
687
+ }
688
+
689
+ // ---- Identifiers and `this`
690
+
691
+ export function checkIdentifier(c: Checker, node: Identifier, checkMode: CheckMode = CheckMode.Normal): Type {
692
+ if (isThisInTypeQuery(node)) return checkThisExpression(c, node);
693
+ const symbol = getResolvedSymbol(c, node);
694
+ if (symbol === c.unknownSymbol) return c.errorType;
695
+ if (symbol === c.argumentsSymbol) {
696
+ if (isInPropertyInitializerOrClassStaticBlock(node, true)) {
697
+ c.error(
698
+ node,
699
+ Diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks,
700
+ );
701
+ return c.errorType;
702
+ }
703
+ return getTypeOfSymbol(c, symbol);
704
+ }
705
+ markIdentifierAliasReferencedInExpression(c, node);
706
+ const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(c, symbol);
707
+ checkDeprecatedIdentifier(c, node, localOrExportSymbol);
708
+ let declaration = localOrExportSymbol.valueDeclaration;
709
+ const immediateDeclaration = declaration;
710
+ // In `const [a, b = a + 1] = [2]`, `a` is `any` while computing the contextual type of `[2]`.
711
+ if (
712
+ declaration !== undefined &&
713
+ declaration.kind === SyntaxKind.BindingElement &&
714
+ c.contextualBindingPatterns.includes(declaration.parent!) &&
715
+ isDescendantOf(node, declaration.parent!)
716
+ )
717
+ return c.nonInferrableAnyType;
718
+ let t = getNarrowableTypeForReference(c, getNarrowedTypeOfSymbol(c, localOrExportSymbol, node), node, checkMode);
719
+ const assignmentKind = getAssignmentTargetKind(node);
720
+ if (assignmentKind !== AssignmentKind.None) {
721
+ if ((localOrExportSymbol.flags & SymbolFlags.Variable) === 0) {
722
+ let message = Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable;
723
+ if ((localOrExportSymbol.flags & SymbolFlags.Enum) !== 0)
724
+ message = Diagnostics.Cannot_assign_to_0_because_it_is_an_enum;
725
+ else if ((localOrExportSymbol.flags & SymbolFlags.Class) !== 0)
726
+ message = Diagnostics.Cannot_assign_to_0_because_it_is_a_class;
727
+ else if ((localOrExportSymbol.flags & SymbolFlags.Module) !== 0)
728
+ message = Diagnostics.Cannot_assign_to_0_because_it_is_a_namespace;
729
+ else if ((localOrExportSymbol.flags & SymbolFlags.Function) !== 0)
730
+ message = Diagnostics.Cannot_assign_to_0_because_it_is_a_function;
731
+ else if ((localOrExportSymbol.flags & SymbolFlags.Alias) !== 0)
732
+ message = Diagnostics.Cannot_assign_to_0_because_it_is_an_import;
733
+ c.error(node, message, symbolToString(c, symbol));
734
+ return c.errorType;
735
+ }
736
+ if (isReadonlySymbol(c, localOrExportSymbol)) {
737
+ c.error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant, symbolToString(c, symbol));
738
+ return c.errorType;
739
+ }
740
+ }
741
+ const isAlias = (localOrExportSymbol.flags & SymbolFlags.Alias) !== 0;
742
+ // Only variables and parameters outside assignment targets are narrowed.
743
+ if ((localOrExportSymbol.flags & SymbolFlags.Variable) !== 0) {
744
+ if (assignmentKind === AssignmentKind.Definite)
745
+ return isInCompoundLikeAssignment(node) ? getBaseTypeOfLiteralType(c, t) : t;
746
+ } else if (isAlias) declaration = getDeclarationOfAliasSymbol(symbol);
747
+ else return t;
748
+ if (declaration === undefined) return t;
749
+ const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
750
+ // The CommonJS `module` symbol is declared by its source file.
751
+ const declarationContainer = declaration.parent !== undefined ? getControlFlowContainer(declaration) : undefined;
752
+ let flowContainer = getControlFlowContainer(node);
753
+ const isOuterVariable = flowContainer !== declarationContainer;
754
+ const isModuleExports = (symbol.flags & SymbolFlags.ModuleExports) !== 0;
755
+ const typeIsAutomatic = t === c.autoType || t === c.autoArrayType;
756
+ const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent!.kind === SyntaxKind.NonNullExpression;
757
+ // Closures see narrowings of constants, and of variables past their last assignment.
758
+ while (
759
+ flowContainer !== declarationContainer &&
760
+ (isFunctionExpressionOrArrowFunction(flowContainer) ||
761
+ isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) &&
762
+ ((isConstantVariable(c, localOrExportSymbol) && t !== c.autoArrayType) ||
763
+ (isParameterOrMutableLocalVariable(c, localOrExportSymbol) && isPastLastAssignment(c, localOrExportSymbol, node)))
764
+ )
765
+ flowContainer = getControlFlowContainer(flowContainer);
766
+ const isNeverInitialized =
767
+ immediateDeclaration !== undefined &&
768
+ immediateDeclaration.kind === SyntaxKind.VariableDeclaration &&
769
+ immediateDeclaration.parent!.parent!.kind !== SyntaxKind.ForInStatement &&
770
+ immediateDeclaration.parent!.parent!.kind !== SyntaxKind.ForOfStatement &&
771
+ getInitializer(immediateDeclaration) === undefined &&
772
+ (immediateDeclaration as VariableDeclaration).exclamationToken === undefined &&
773
+ isMutableLocalVariableDeclaration(immediateDeclaration) &&
774
+ !isSymbolAssignedDefinitely(c, localOrExportSymbol);
775
+ const assumeInitialized =
776
+ isParameter ||
777
+ isAlias ||
778
+ (isOuterVariable && !isNeverInitialized) ||
779
+ isSpreadDestructuringAssignmentTarget(node) ||
780
+ isModuleExports ||
781
+ isSameScopedBindingElement(node, declaration) ||
782
+ (t !== c.autoType &&
783
+ t !== c.autoArrayType &&
784
+ (!c.strictNullChecks ||
785
+ (t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
786
+ isPartOfTypeQuery(node) ||
787
+ isInAmbientOrTypeNode(node) ||
788
+ node.parent!.kind === SyntaxKind.ExportSpecifier)) ||
789
+ node.parent!.kind === SyntaxKind.NonNullExpression ||
790
+ (declaration.kind === SyntaxKind.VariableDeclaration &&
791
+ (declaration as VariableDeclaration).exclamationToken !== undefined) ||
792
+ (declaration.flags & NodeFlags.Ambient) !== 0;
793
+ let initialType: Type;
794
+ if (isAutomaticTypeInNonNull) initialType = c.undefinedType;
795
+ else if (assumeInitialized && isParameter) initialType = removeOptionalityFromDeclaredType(c, t, declaration);
796
+ else if (assumeInitialized) initialType = t;
797
+ else if (typeIsAutomatic) initialType = c.undefinedType;
798
+ else initialType = getOptionalType(c, t, false);
799
+ let flowType = getFlowTypeOfReference(c, node, t, initialType, flowContainer);
800
+ if (isAutomaticTypeInNonNull) flowType = getNonNullableType(c, flowType);
801
+ if (!isEvolvingArrayOperationTarget(c, node) && typeIsAutomatic) {
802
+ if (flowType === c.autoType || flowType === c.autoArrayType) {
803
+ if (c.noImplicitAny) {
804
+ c.error(
805
+ getNameOfDeclaration(declaration),
806
+ Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined,
807
+ symbolToString(c, symbol),
808
+ typeToString(c, flowType),
809
+ );
810
+ c.error(
811
+ node,
812
+ Diagnostics.Variable_0_implicitly_has_an_1_type,
813
+ symbolToString(c, symbol),
814
+ typeToString(c, flowType),
815
+ );
816
+ }
817
+ return convertAutoToAny(c, flowType);
818
+ }
819
+ } else if (!assumeInitialized && !containsUndefinedType(t) && containsUndefinedType(flowType)) {
820
+ c.error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(c, symbol));
821
+ return t;
822
+ }
823
+ return assignmentKind !== AssignmentKind.None ? getBaseTypeOfLiteralType(c, flowType) : flowType;
824
+ }
825
+
826
+ /**
827
+ * A reference's type with union constraints substituted for generic types where only the
828
+ * constraint matters, so narrowing can apply: in constraint positions like `x.p`, or with a
829
+ * non-generic contextual type.
830
+ */
831
+ export function getNarrowableTypeForReference(
832
+ c: Checker,
833
+ t: Type,
834
+ reference: Node,
835
+ checkMode: CheckMode = CheckMode.Normal,
836
+ ): Type {
837
+ if (isNoInferType(c, t)) t = (t as SubstitutionType).baseType;
838
+ const substituteConstraints =
839
+ (checkMode & CheckMode.Inferential) === 0 &&
840
+ someTypeIsGenericWithUnionConstraint(c, t) &&
841
+ (isConstraintPosition(c, t, reference) || hasContextualTypeWithNoGenericTypes(c, reference, checkMode));
842
+ return substituteConstraints ? mapToBaseConstraintOrType(c, t) : t;
843
+ }
844
+
845
+ export function someTypeIsGenericWithUnionConstraint(c: Checker, t: Type): boolean {
846
+ if ((t.flags & TypeFlags.Union) === 0) return isGenericTypeWithUnionConstraint(c, t);
847
+ for (const u of typesOf(t)) if (isGenericTypeWithUnionConstraint(c, u)) return true;
848
+ return false;
849
+ }
850
+
851
+ function isConstraintPosition(c: Checker, t: Type, node: Node): boolean {
852
+ const parent = node.parent!;
853
+ // `obj[x]` keeps `T[K]` when both are generic and obj's constraint isn't nullable.
854
+ return (
855
+ parent.kind === SyntaxKind.PropertyAccessExpression ||
856
+ parent.kind === SyntaxKind.QualifiedName ||
857
+ ((parent.kind === SyntaxKind.CallExpression || parent.kind === SyntaxKind.NewExpression) &&
858
+ getExpression(parent) === node) ||
859
+ (parent.kind === SyntaxKind.ElementAccessExpression &&
860
+ getExpression(parent) === node &&
861
+ !(
862
+ someType(t, (u) => isGenericTypeWithoutNullableConstraint(c, u)) &&
863
+ isGenericIndexType(c, getTypeOfExpression(c, (parent as ElementAccessExpression).argumentExpression))
864
+ ))
865
+ );
866
+ }
867
+
868
+ function isGenericTypeWithUnionConstraint(c: Checker, t: Type): boolean {
869
+ if ((t.flags & TypeFlags.Intersection) !== 0) {
870
+ for (const u of typesOf(t)) if (isGenericTypeWithUnionConstraint(c, u)) return true;
871
+ return false;
872
+ }
873
+ return (
874
+ (t.flags & TypeFlags.Instantiable) !== 0 &&
875
+ (getBaseConstraintOrType(c, t).flags & (TypeFlags.Nullable | TypeFlags.Union)) !== 0
876
+ );
877
+ }
878
+
879
+ function isGenericTypeWithoutNullableConstraint(c: Checker, t: Type): boolean {
880
+ if ((t.flags & TypeFlags.Intersection) !== 0) {
881
+ for (const u of typesOf(t)) if (isGenericTypeWithoutNullableConstraint(c, u)) return true;
882
+ return false;
883
+ }
884
+ return (
885
+ (t.flags & TypeFlags.Instantiable) !== 0 && !maybeTypeOfKind(getBaseConstraintOrType(c, t), TypeFlags.Nullable)
886
+ );
887
+ }
888
+
889
+ function hasContextualTypeWithNoGenericTypes(c: Checker, node: Node, checkMode: CheckMode): boolean {
890
+ // JSX tag names are excluded: their contextual type resolves the tag itself.
891
+ if (
892
+ node.kind !== SyntaxKind.Identifier &&
893
+ node.kind !== SyntaxKind.PropertyAccessExpression &&
894
+ node.kind !== SyntaxKind.ElementAccessExpression
895
+ )
896
+ return false;
897
+ const parent = node.parent!;
898
+ if (
899
+ (parent.kind === SyntaxKind.JsxOpeningElement || parent.kind === SyntaxKind.JsxSelfClosingElement) &&
900
+ getTagName(parent) === node
901
+ )
902
+ return false;
903
+ // Rest elements skip binding pattern contextual types, so their type stays generic when possible.
904
+ const contextualType = getContextualTypeEx(
905
+ c,
906
+ node,
907
+ (checkMode & CheckMode.RestBindingElement) !== 0 ? ContextFlags.SkipBindingPatterns : ContextFlags.None,
908
+ );
909
+ return contextualType !== undefined && !isGenericType(c, contextualType);
910
+ }
911
+
912
+ /** Whether `t` is or includes undefined, which includes the missing type of an optional property or element. */
913
+ function containsUndefinedType(t: Type): boolean {
914
+ const u = (t.flags & TypeFlags.Union) !== 0 ? (t as UnionType).types[0]! : t;
915
+ return (u.flags & TypeFlags.Undefined) !== 0;
916
+ }
917
+
918
+ function isDescendantOf(node: Node, ancestor: Node): boolean {
919
+ for (let current: Node | undefined = node; current !== undefined; current = current.parent)
920
+ if (current === ancestor) return true;
921
+ return false;
922
+ }
923
+
924
+ export function isInAmbientOrTypeNode(node: Node): boolean {
925
+ if ((node.flags & NodeFlags.Ambient) !== 0) return true;
926
+ for (let current: Node | undefined = node; current !== undefined; current = current.parent) {
927
+ if (
928
+ current.kind === SyntaxKind.InterfaceDeclaration ||
929
+ current.kind === SyntaxKind.TypeAliasDeclaration ||
930
+ current.kind === SyntaxKind.TypeLiteral
931
+ )
932
+ return true;
933
+ }
934
+ return false;
935
+ }
936
+
937
+ export function checkThisExpression(c: Checker, node: Node): Type {
938
+ // Stop at the first arrow function to tell whether `this` is captured.
939
+ let container = getThisContainer(node, true, true);
940
+ let capturedByArrowFunction = false;
941
+ let thisInComputedPropertyName = false;
942
+ if (container.kind === SyntaxKind.Constructor)
943
+ checkThisBeforeSuper(
944
+ c,
945
+ node,
946
+ container,
947
+ Diagnostics.X_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class,
948
+ );
949
+ for (;;) {
950
+ // Skip arrow functions to the real owner of `this`.
951
+ if (container.kind === SyntaxKind.ArrowFunction) {
952
+ container = getThisContainer(container, false, !thisInComputedPropertyName);
953
+ capturedByArrowFunction = true;
954
+ }
955
+ if (container.kind === SyntaxKind.ComputedPropertyName) {
956
+ container = getThisContainer(container, !capturedByArrowFunction, false);
957
+ thisInComputedPropertyName = true;
958
+ continue;
959
+ }
960
+ break;
961
+ }
962
+ checkThisInStaticClassFieldInitializerInDecoratedClass(c, node, container);
963
+ if (thisInComputedPropertyName) c.error(node, Diagnostics.X_this_cannot_be_referenced_in_a_computed_property_name);
964
+ else if (container.kind === SyntaxKind.ModuleDeclaration)
965
+ c.error(node, Diagnostics.X_this_cannot_be_referenced_in_a_module_or_namespace_body);
966
+ else if (container.kind === SyntaxKind.EnumDeclaration)
967
+ c.error(node, Diagnostics.X_this_cannot_be_referenced_in_current_location);
968
+ const t = tryGetThisTypeAt(c, node, container);
969
+ if (c.noImplicitThis) {
970
+ const globalThisType = getTypeOfSymbol(c, c.globalThisSymbol);
971
+ if (t === globalThisType && capturedByArrowFunction)
972
+ c.error(node, Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this);
973
+ else if (t === undefined)
974
+ c.error(node, Diagnostics.X_this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation);
975
+ }
976
+ return t ?? c.anyType;
977
+ }
978
+
979
+ function tryGetThisTypeAt(c: Checker, node: Node, container: Node): Type | undefined {
980
+ if (isFunctionLike(container) && container.kind !== SyntaxKind.Constructor) {
981
+ const thisType =
982
+ getThisTypeOfSignature(
983
+ c,
984
+ getSignatureOfFullSignatureType(c, container) ?? getSignatureFromDeclaration(c, container),
985
+ ) ?? getContextualThisParameterType(c, container);
986
+ if (thisType !== undefined) return getFlowTypeOfReference(c, node, thisType, thisType, undefined);
987
+ }
988
+ const parent = container.parent;
989
+ if (parent !== undefined && isClassLike(parent)) {
990
+ const classSymbol = getSymbolOfDeclaration(c, parent);
991
+ if (classSymbol === undefined) return c.anyType;
992
+ const t =
993
+ isStatic(container) || container.kind === SyntaxKind.ClassStaticBlockDeclaration
994
+ ? getTypeOfSymbol(c, classSymbol)
995
+ : getDeclaredTypeOfClassOrInterface(c, getMergedSymbol(c, classSymbol)).thisType;
996
+ return t !== undefined ? getFlowTypeOfReference(c, node, t, t, undefined) : c.anyType;
997
+ }
998
+ if (container.kind === SyntaxKind.SourceFile) {
999
+ if ((container as SourceFile).externalModuleIndicator !== undefined) return c.undefinedType;
1000
+ return getTypeOfSymbol(c, c.globalThisSymbol);
1001
+ }
1002
+ return undefined;
1003
+ }
1004
+
1005
+ /** The `this` type of a function expression or method from its context, such as its object literal. */
1006
+ export function getContextualThisParameterType(c: Checker, func: Node): Type | undefined {
1007
+ if (func.kind === SyntaxKind.ArrowFunction) return undefined;
1008
+ if (isContextSensitiveFunctionOrObjectLiteralMethod(c, func)) {
1009
+ const signature = getContextualSignatureForFunctionLikeDeclaration(c, func);
1010
+ if (signature !== undefined && signature.thisParameter !== undefined)
1011
+ return getTypeOfSymbol(c, signature.thisParameter);
1012
+ }
1013
+ if (!c.noImplicitThis && !isInJSFile(func)) return undefined;
1014
+ const literal = getContainingObjectLiteral(func);
1015
+ if (literal !== undefined) return getThisTypeOfObjectLiteralMember(c, literal);
1016
+ return getThisTypeOfAssignedFunction(c, func);
1017
+ }
1018
+
1019
+ function getContainingObjectLiteral(func: Node): Node | undefined {
1020
+ const parent = func.parent!;
1021
+ if (
1022
+ (func.kind === SyntaxKind.MethodDeclaration ||
1023
+ func.kind === SyntaxKind.GetAccessor ||
1024
+ func.kind === SyntaxKind.SetAccessor) &&
1025
+ parent.kind === SyntaxKind.ObjectLiteralExpression
1026
+ )
1027
+ return parent;
1028
+ if (func.kind === SyntaxKind.FunctionExpression && parent.kind === SyntaxKind.PropertyAssignment)
1029
+ return parent.parent;
1030
+ return undefined;
1031
+ }
1032
+
1033
+ // ---- Literals
1034
+
1035
+ function checkTemplateExpression(c: Checker, node: TemplateExpression): Type {
1036
+ const texts = [getText(node.head)];
1037
+ const types: Type[] = [];
1038
+ for (const span of node.templateSpans.nodes) {
1039
+ const expression = getExpression(span)!;
1040
+ const t = checkExpression(c, expression);
1041
+ if (
1042
+ maybeTypeOfKind(t, TypeFlags.ESSymbolLike) ||
1043
+ maybeTypeOfKind(getBaseConstraintOrType(c, t), TypeFlags.ESSymbolLike)
1044
+ )
1045
+ c.error(
1046
+ expression,
1047
+ Diagnostics.Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String,
1048
+ );
1049
+ texts.push(getText((span as TemplateSpan).literal));
1050
+ types.push(isTypeAssignableTo(c, t, c.templateConstraintType) ? t : c.stringType);
1051
+ }
1052
+ if (node.parent!.kind !== SyntaxKind.TaggedTemplateExpression) {
1053
+ const evaluated = evaluate(c, node, node);
1054
+ if (evaluated.kind === EvaluatedKind.String)
1055
+ return getFreshTypeOfLiteralType(c, getStringLiteralType(c, evaluated.stringValue));
1056
+ }
1057
+ if (
1058
+ isConstContext(c, node) ||
1059
+ isTemplateLiteralContext(node) ||
1060
+ someType(getContextualType(c, node) ?? c.unknownType, (t) => isTemplateLiteralContextualType(c, t))
1061
+ )
1062
+ return getTemplateLiteralType(c, texts, types);
1063
+ return c.stringType;
1064
+ }
1065
+
1066
+ function isTemplateLiteralContext(node: Node): boolean {
1067
+ const parent = node.parent!;
1068
+ return (
1069
+ (parent.kind === SyntaxKind.ParenthesizedExpression && isTemplateLiteralContext(parent)) ||
1070
+ (parent.kind === SyntaxKind.ElementAccessExpression &&
1071
+ (parent as ElementAccessExpression).argumentExpression === node)
1072
+ );
1073
+ }
1074
+
1075
+ function isTemplateLiteralContextualType(c: Checker, t: Type): boolean {
1076
+ return (
1077
+ (t.flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral)) !== 0 ||
1078
+ ((t.flags & TypeFlags.InstantiableNonPrimitive) !== 0 &&
1079
+ maybeTypeOfKind(getBaseConstraintOfType(c, t) ?? c.unknownType, TypeFlags.StringLike))
1080
+ );
1081
+ }
1082
+
1083
+ function checkSpreadExpression(c: Checker, node: SpreadElement, checkMode: CheckMode): Type {
1084
+ const arrayOrIterableType = checkExpressionEx(c, node.expression, checkMode);
1085
+ return checkIteratedTypeOrElementType(c, IterationUse.Spread, arrayOrIterableType, c.undefinedType, node.expression);
1086
+ }
1087
+
1088
+ function checkArrayLiteral(c: Checker, node: ArrayLiteralExpression, checkMode: CheckMode): Type {
1089
+ const elements = node.elements.nodes;
1090
+ const elementTypes: Type[] = [];
1091
+ const elementInfos: TupleElementInfo[] = [];
1092
+ // The elements' contextual types come from the literal's, computed once.
1093
+ pushCachedContextualType(c, node);
1094
+ const inDestructuringPattern = isAssignmentTarget(node);
1095
+ const inConstContext = isConstContext(c, node);
1096
+ const contextualType = getApparentTypeOfContextualType(c, node);
1097
+ const inTupleContext =
1098
+ isSpreadIntoCallOrNew(node) ||
1099
+ (contextualType !== undefined && someType(contextualType, (t) => isTupleLikeContext(c, t)));
1100
+ let hasOmittedExpression = false;
1101
+ for (const e of elements) {
1102
+ if (e.kind === SyntaxKind.SpreadElement) {
1103
+ const spreadType = checkExpressionEx(c, (e as SpreadElement).expression, checkMode);
1104
+ if (isArrayLikeType(c, spreadType)) {
1105
+ elementTypes.push(spreadType);
1106
+ elementInfos.push(new TupleElementInfo(ElementFlags.Variadic, undefined));
1107
+ } else if (inDestructuringPattern) {
1108
+ // `[...c] = ...` makes `c` a rest target that only provides a contextual type, so it's not
1109
+ // checked as iterable.
1110
+ const restElementType =
1111
+ getIndexTypeOfType(c, spreadType, c.numberType) ??
1112
+ getIteratedTypeOrElementType(c, IterationUse.Destructuring, spreadType, c.undefinedType, undefined, false) ??
1113
+ c.unknownType;
1114
+ elementTypes.push(restElementType);
1115
+ elementInfos.push(new TupleElementInfo(ElementFlags.Rest, undefined));
1116
+ } else {
1117
+ elementTypes.push(
1118
+ checkIteratedTypeOrElementType(
1119
+ c,
1120
+ IterationUse.Spread,
1121
+ spreadType,
1122
+ c.undefinedType,
1123
+ (e as SpreadElement).expression,
1124
+ ),
1125
+ );
1126
+ elementInfos.push(new TupleElementInfo(ElementFlags.Rest, undefined));
1127
+ }
1128
+ } else if (c.exactOptionalPropertyTypes && e.kind === SyntaxKind.OmittedExpression) {
1129
+ hasOmittedExpression = true;
1130
+ elementTypes.push(c.undefinedOrMissingType);
1131
+ elementInfos.push(new TupleElementInfo(ElementFlags.Optional, undefined));
1132
+ } else {
1133
+ const t =
1134
+ e.kind === SyntaxKind.OmittedExpression
1135
+ ? c.undefinedWideningType
1136
+ : checkExpressionForMutableLocationEx(c, e, checkMode);
1137
+ if (
1138
+ inTupleContext &&
1139
+ (checkMode & CheckMode.Inferential) !== 0 &&
1140
+ (checkMode & CheckMode.SkipContextSensitive) === 0 &&
1141
+ isContextSensitive(c, e)
1142
+ ) {
1143
+ // Inferences flowing between context-sensitive tuple elements are made before fixing.
1144
+ const inferenceContext = getInferenceContext(c, node);
1145
+ if (inferenceContext !== undefined) addIntraExpressionInferenceSite(inferenceContext, e, t);
1146
+ }
1147
+ elementTypes.push(addOptionality(c, t, true, hasOmittedExpression));
1148
+ elementInfos.push(
1149
+ new TupleElementInfo(hasOmittedExpression ? ElementFlags.Optional : ElementFlags.Required, undefined),
1150
+ );
1151
+ }
1152
+ }
1153
+ popContextualType(c);
1154
+ if (inDestructuringPattern) return createTupleTypeEx(c, elementTypes, elementInfos, false);
1155
+ if (inConstContext || inTupleContext || (checkMode & CheckMode.ForceTuple) !== 0)
1156
+ return createArrayLiteralType(
1157
+ c,
1158
+ createTupleTypeEx(
1159
+ c,
1160
+ elementTypes,
1161
+ elementInfos,
1162
+ inConstContext &&
1163
+ !(contextualType !== undefined && someType(contextualType, (t) => isMutableArrayLikeType(c, t))),
1164
+ ),
1165
+ );
1166
+ let elementType: Type;
1167
+ if (elementTypes.length > 0) {
1168
+ for (let i = 0; i < elementTypes.length; i++)
1169
+ if ((elementInfos[i]!.flags & ElementFlags.Variadic) !== 0)
1170
+ elementTypes[i] =
1171
+ getIndexedAccessTypeOrUndefinedEx(
1172
+ c,
1173
+ elementTypes[i]!,
1174
+ c.numberType,
1175
+ AccessFlags.None,
1176
+ undefined,
1177
+ undefined,
1178
+ ) ?? c.anyType;
1179
+ elementType = getUnionTypeEx(c, elementTypes, UnionReduction.Subtype, undefined, undefined);
1180
+ } else elementType = c.strictNullChecks ? c.implicitNeverType : c.undefinedWideningType;
1181
+ return createArrayLiteralType(c, createArrayTypeEx(c, elementType, inConstContext));
1182
+ }
1183
+
1184
+ function isSpreadIntoCallOrNew(node: Node): boolean {
1185
+ let parent = node.parent!;
1186
+ while (parent.kind === SyntaxKind.ParenthesizedExpression) parent = parent.parent!;
1187
+ return (
1188
+ parent.kind === SyntaxKind.SpreadElement &&
1189
+ (parent.parent!.kind === SyntaxKind.CallExpression || parent.parent!.kind === SyntaxKind.NewExpression)
1190
+ );
1191
+ }
1192
+
1193
+ function isTupleLikeContext(c: Checker, t: Type): boolean {
1194
+ if (isTupleLikeType(c, t)) return true;
1195
+ if (!isGenericMappedType(c, t)) return false;
1196
+ const mapped = t as MappedType;
1197
+ if (mapped.nameType !== undefined) return false;
1198
+ const target = mapped.target;
1199
+ return getHomomorphicTypeVariable(c, target !== undefined ? (target as MappedType) : mapped) !== undefined;
1200
+ }
1201
+
1202
+ export function isTupleLikeType(c: Checker, t: Type): boolean {
1203
+ if (isTupleType(t) || getPropertyOfType(c, t, '0') !== undefined) return true;
1204
+ if (!isArrayLikeType(c, t)) return false;
1205
+ const lengthType = getTypeOfPropertyOfType(c, t, 'length');
1206
+ return lengthType !== undefined && everyType(lengthType, (u) => (u.flags & TypeFlags.NumberLiteral) !== 0);
1207
+ }
1208
+
1209
+ /** Whether `t` is a mutable array, a mutable tuple, or assignable to `any[]`. */
1210
+ export function isMutableArrayLikeType(c: Checker, t: Type): boolean {
1211
+ return (
1212
+ isMutableArrayOrTuple(c, t) ||
1213
+ ((t.flags & (TypeFlags.Any | TypeFlags.Nullable)) === 0 && isTypeAssignableTo(c, t, c.anyArrayType))
1214
+ );
1215
+ }
1216
+
1217
+ function createArrayLiteralType(c: Checker, t: Type): Type {
1218
+ if ((t.objectFlags & ObjectFlags.Reference) === 0) return t;
1219
+ const key = cachedTypeKey(CachedTypeKind.ArrayLiteral, t.id);
1220
+ let literal = c.cachedTypesById.get(key);
1221
+ if (literal === undefined) {
1222
+ literal = cloneTypeReference(c, t as TypeReference);
1223
+ literal.objectFlags |= ObjectFlags.ArrayLiteral | ObjectFlags.ContainsObjectOrArrayLiteral;
1224
+ c.cachedTypesById.set(key, literal);
1225
+ }
1226
+ return literal;
1227
+ }
1228
+
1229
+ /** The name of an object literal element, or undefined when it's computed and not a literal. */
1230
+ export function getPropertyNameOfObjectLiteralElement(c: Checker, element: Node): string | undefined {
1231
+ const name = getName(element);
1232
+ if (name === undefined) return undefined;
1233
+ switch (name.kind) {
1234
+ case SyntaxKind.Identifier:
1235
+ case SyntaxKind.PrivateIdentifier:
1236
+ case SyntaxKind.StringLiteral:
1237
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
1238
+ return getText(name);
1239
+ case SyntaxKind.NumericLiteral:
1240
+ return String(Number(getText(name)));
1241
+ case SyntaxKind.BigIntLiteral:
1242
+ return parseBigIntText(getText(name));
1243
+ case SyntaxKind.ComputedPropertyName: {
1244
+ const t = checkComputedPropertyName(c, name);
1245
+ return isTypeUsableAsPropertyName(t) ? getPropertyNameFromType(t) : undefined;
1246
+ }
1247
+ }
1248
+ return undefined;
1249
+ }
1250
+
1251
+ /** Whether `node` is in an `as const` context, where literals keep their types. */
1252
+ export function isConstContext(c: Checker, node: Node): boolean {
1253
+ const parent = node.parent;
1254
+ if (parent === undefined) return false;
1255
+ // Literals contextually typed by a `const` type parameter are in a const context.
1256
+ if (isValidConstAssertionArgument(c, node) && isConstTypeVariable(c, getContextualType(c, node), 0)) return true;
1257
+ switch (parent.kind) {
1258
+ case SyntaxKind.AsExpression:
1259
+ case SyntaxKind.TypeAssertionExpression:
1260
+ return isConstTypeReference(getType(parent)!);
1261
+ // As in tsgo, a const context does not reach through `satisfies` or into the branches of a
1262
+ // conditional expression: those are in one only when their own contextual type is a `const`
1263
+ // type parameter (above).
1264
+ case SyntaxKind.ParenthesizedExpression:
1265
+ case SyntaxKind.ArrayLiteralExpression:
1266
+ case SyntaxKind.SpreadElement:
1267
+ return isConstContext(c, parent);
1268
+ case SyntaxKind.PropertyAssignment:
1269
+ case SyntaxKind.ShorthandPropertyAssignment:
1270
+ return isConstContext(c, parent.parent!);
1271
+ case SyntaxKind.TemplateSpan:
1272
+ return isConstContext(c, parent.parent!);
1273
+ }
1274
+ return false;
1275
+ }
1276
+
1277
+ /** Whether `as const` applies to the expression: a literal, or a reference to an enum member. */
1278
+ function isValidConstAssertionArgument(c: Checker, node: Node): boolean {
1279
+ switch (node.kind) {
1280
+ case SyntaxKind.StringLiteral:
1281
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
1282
+ case SyntaxKind.NumericLiteral:
1283
+ case SyntaxKind.BigIntLiteral:
1284
+ case SyntaxKind.TrueKeyword:
1285
+ case SyntaxKind.FalseKeyword:
1286
+ case SyntaxKind.ArrayLiteralExpression:
1287
+ case SyntaxKind.ObjectLiteralExpression:
1288
+ case SyntaxKind.TemplateExpression:
1289
+ return true;
1290
+ case SyntaxKind.ParenthesizedExpression:
1291
+ return isValidConstAssertionArgument(c, getExpression(node)!);
1292
+ case SyntaxKind.PrefixUnaryExpression: {
1293
+ const unary = node as PrefixUnaryExpression;
1294
+ const kind = unary.operand.kind;
1295
+ return (
1296
+ (unary.operator === SyntaxKind.MinusToken &&
1297
+ (kind === SyntaxKind.NumericLiteral || kind === SyntaxKind.BigIntLiteral)) ||
1298
+ (unary.operator === SyntaxKind.PlusToken && kind === SyntaxKind.NumericLiteral)
1299
+ );
1300
+ }
1301
+ case SyntaxKind.PropertyAccessExpression:
1302
+ case SyntaxKind.ElementAccessExpression: {
1303
+ const expr = skipParentheses(getExpression(node)!);
1304
+ const symbol = isEntityNameExpression(expr, false)
1305
+ ? resolveEntityName(c, expr, SymbolFlags.Value, true, false, undefined)
1306
+ : undefined;
1307
+ return symbol !== undefined && (symbol.flags & SymbolFlags.Enum) !== 0;
1308
+ }
1309
+ }
1310
+ return false;
1311
+ }
1312
+
1313
+ export function isConstTypeReference(node: Node): boolean {
1314
+ if (node.kind !== SyntaxKind.TypeReference) return false;
1315
+ const ref = node as TypeReferenceNode;
1316
+ return (
1317
+ ref.typeName.kind === SyntaxKind.Identifier && getText(ref.typeName) === 'const' && ref.typeArguments === undefined
1318
+ );
1319
+ }
1320
+
1321
+ /** Widens a literal type unless the contextual type calls for literals of its kind. */
1322
+ export function getWidenedLiteralLikeTypeForContextualType(
1323
+ c: Checker,
1324
+ t: Type,
1325
+ contextualType: Type | undefined,
1326
+ ): Type {
1327
+ if (!isLiteralOfContextualType(c, t, contextualType))
1328
+ return getWidenedUniqueESSymbolType(c, getWidenedLiteralType(c, t));
1329
+ return getRegularTypeOfLiteralType(c, t);
1330
+ }
1331
+
1332
+ export function isLiteralOfContextualType(c: Checker, candidate: Type, contextualType: Type | undefined): boolean {
1333
+ if (contextualType === undefined) return false;
1334
+ if ((contextualType.flags & TypeFlags.UnionOrIntersection) !== 0) {
1335
+ for (const t of typesOf(contextualType)) if (isLiteralOfContextualType(c, candidate, t)) return true;
1336
+ return false;
1337
+ }
1338
+ if ((contextualType.flags & TypeFlags.InstantiableNonPrimitive) !== 0) {
1339
+ const constraint = getBaseConstraintOfType(c, contextualType) ?? c.unknownType;
1340
+ return (
1341
+ (maybeTypeOfKind(constraint, TypeFlags.String) && maybeTypeOfKind(candidate, TypeFlags.StringLiteral)) ||
1342
+ (maybeTypeOfKind(constraint, TypeFlags.Number) && maybeTypeOfKind(candidate, TypeFlags.NumberLiteral)) ||
1343
+ (maybeTypeOfKind(constraint, TypeFlags.BigInt) && maybeTypeOfKind(candidate, TypeFlags.BigIntLiteral)) ||
1344
+ (maybeTypeOfKind(constraint, TypeFlags.ESSymbol) && maybeTypeOfKind(candidate, TypeFlags.UniqueESSymbol)) ||
1345
+ isLiteralOfContextualType(c, candidate, constraint)
1346
+ );
1347
+ }
1348
+ return (
1349
+ ((contextualType.flags &
1350
+ (TypeFlags.StringLiteral | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping)) !==
1351
+ 0 &&
1352
+ maybeTypeOfKind(candidate, TypeFlags.StringLiteral)) ||
1353
+ ((contextualType.flags & TypeFlags.NumberLiteral) !== 0 && maybeTypeOfKind(candidate, TypeFlags.NumberLiteral)) ||
1354
+ ((contextualType.flags & TypeFlags.BigIntLiteral) !== 0 && maybeTypeOfKind(candidate, TypeFlags.BigIntLiteral)) ||
1355
+ ((contextualType.flags & TypeFlags.BooleanLiteral) !== 0 && maybeTypeOfKind(candidate, TypeFlags.BooleanLiteral)) ||
1356
+ ((contextualType.flags & TypeFlags.UniqueESSymbol) !== 0 && maybeTypeOfKind(candidate, TypeFlags.UniqueESSymbol))
1357
+ );
1358
+ }
1359
+
1360
+ // ---- Property and element access
1361
+
1362
+ /**
1363
+ * The type of an expression used as an object, with `null` and `undefined` removed. Without
1364
+ * narrowing, nullability errors are only reported where no narrowing could apply.
1365
+ */
1366
+ export function checkNonNullExpression(c: Checker, node: Node): Type {
1367
+ return checkNonNullType(c, checkExpression(c, node), node);
1368
+ }
1369
+
1370
+ export function checkNonNullType(c: Checker, t: Type, node: Node): Type {
1371
+ return checkNonNullTypeEx(c, t, node, false);
1372
+ }
1373
+
1374
+ /** `checkNonNullType`, reporting a possibly nullish callee of a call when `isCallee`. */
1375
+ export function checkNonNullTypeEx(c: Checker, t: Type, node: Node, isCallee: boolean): Type {
1376
+ if (c.strictNullChecks && (t.flags & TypeFlags.Unknown) !== 0) {
1377
+ if (isEntityNameExpression(node, false)) {
1378
+ const nodeText = entityNameToString(node);
1379
+ if (nodeText.length < 100) {
1380
+ c.error(node, Diagnostics.X_0_is_of_type_unknown, nodeText);
1381
+ return c.errorType;
1382
+ }
1383
+ }
1384
+ c.error(node, Diagnostics.Object_is_of_type_unknown);
1385
+ return c.errorType;
1386
+ }
1387
+ const facts = getTypeFacts(c, t, TypeFacts.IsUndefinedOrNull);
1388
+ if ((facts & TypeFacts.IsUndefinedOrNull) !== 0) {
1389
+ if (isCallee) reportCannotInvokePossiblyNullOrUndefinedError(c, node, facts);
1390
+ else reportObjectPossiblyNullOrUndefinedError(c, node, facts);
1391
+ const nonNullable = getNonNullableType(c, t);
1392
+ return (nonNullable.flags & (TypeFlags.Nullable | TypeFlags.Never)) !== 0 ? c.errorType : nonNullable;
1393
+ }
1394
+ return t;
1395
+ }
1396
+
1397
+ function reportCannotInvokePossiblyNullOrUndefinedError(c: Checker, node: Node, facts: TypeFacts): void {
1398
+ c.error(
1399
+ node,
1400
+ (facts & TypeFacts.IsUndefined) !== 0
1401
+ ? (facts & TypeFacts.IsNull) !== 0
1402
+ ? Diagnostics.Cannot_invoke_an_object_which_is_possibly_null_or_undefined
1403
+ : Diagnostics.Cannot_invoke_an_object_which_is_possibly_undefined
1404
+ : Diagnostics.Cannot_invoke_an_object_which_is_possibly_null,
1405
+ );
1406
+ }
1407
+
1408
+ function reportObjectPossiblyNullOrUndefinedError(c: Checker, node: Node, facts: TypeFacts): void {
1409
+ if (node.kind === SyntaxKind.NullKeyword) {
1410
+ c.error(node, Diagnostics.The_value_0_cannot_be_used_here, 'null');
1411
+ return;
1412
+ }
1413
+ const nodeText = isEntityNameExpression(node, false) ? entityNameToString(node) : '';
1414
+ if (nodeText !== '' && nodeText.length < 100) {
1415
+ if (node.kind === SyntaxKind.Identifier && nodeText === 'undefined') {
1416
+ c.error(node, Diagnostics.The_value_0_cannot_be_used_here, 'undefined');
1417
+ return;
1418
+ }
1419
+ c.error(
1420
+ node,
1421
+ (facts & TypeFacts.IsUndefined) !== 0
1422
+ ? (facts & TypeFacts.IsNull) !== 0
1423
+ ? Diagnostics.X_0_is_possibly_null_or_undefined
1424
+ : Diagnostics.X_0_is_possibly_undefined
1425
+ : Diagnostics.X_0_is_possibly_null,
1426
+ nodeText,
1427
+ );
1428
+ } else {
1429
+ c.error(
1430
+ node,
1431
+ (facts & TypeFacts.IsUndefined) !== 0
1432
+ ? (facts & TypeFacts.IsNull) !== 0
1433
+ ? Diagnostics.Object_is_possibly_null_or_undefined
1434
+ : Diagnostics.Object_is_possibly_undefined
1435
+ : Diagnostics.Object_is_possibly_null,
1436
+ );
1437
+ }
1438
+ }
1439
+
1440
+ /** `checkNonNullType`, also reporting a `void` type as possibly undefined. */
1441
+ export function checkNonNullNonVoidType(c: Checker, t: Type, node: Node): Type {
1442
+ const nonNullType = checkNonNullType(c, t, node);
1443
+ if ((nonNullType.flags & TypeFlags.Void) === 0) return nonNullType;
1444
+ if (isEntityNameExpression(node, false)) {
1445
+ const nodeText = entityNameToString(node);
1446
+ if (node.kind === SyntaxKind.Identifier && nodeText === 'undefined') {
1447
+ c.error(node, Diagnostics.The_value_0_cannot_be_used_here, nodeText);
1448
+ return nonNullType;
1449
+ }
1450
+ if (nodeText.length < 100) {
1451
+ c.error(node, Diagnostics.X_0_is_possibly_undefined, nodeText);
1452
+ return nonNullType;
1453
+ }
1454
+ }
1455
+ c.error(node, Diagnostics.Object_is_possibly_undefined);
1456
+ return nonNullType;
1457
+ }
1458
+
1459
+ export function entityNameToString(node: Node): string {
1460
+ switch (node.kind) {
1461
+ case SyntaxKind.Identifier:
1462
+ return getText(node);
1463
+ case SyntaxKind.ThisKeyword:
1464
+ return 'this';
1465
+ case SyntaxKind.PropertyAccessExpression: {
1466
+ const access = node as PropertyAccessExpression;
1467
+ return entityNameToString(access.expression) + '.' + entityNameToString(access.name);
1468
+ }
1469
+ case SyntaxKind.QualifiedName: {
1470
+ const q = node as QualifiedName;
1471
+ return entityNameToString(q.left) + '.' + q.right.text;
1472
+ }
1473
+ }
1474
+ return getText(node);
1475
+ }
1476
+
1477
+ /** The type of `obj.name`; `writeOnly` gives the type it can be assigned, as for compound assignments. */
1478
+ export function checkPropertyAccessExpression(
1479
+ c: Checker,
1480
+ node: PropertyAccessExpression,
1481
+ writeOnly: boolean,
1482
+ checkMode: CheckMode = CheckMode.Normal,
1483
+ ): Type {
1484
+ if (!isOptionalChain(node))
1485
+ return checkPropertyAccessExpressionOrQualifiedName(
1486
+ c,
1487
+ node,
1488
+ node.expression,
1489
+ checkNonNullExpression(c, node.expression),
1490
+ node.name,
1491
+ writeOnly,
1492
+ checkMode,
1493
+ );
1494
+ const leftType = checkExpression(c, node.expression);
1495
+ const nonOptional = getOptionalExpressionType(c, leftType, node.expression);
1496
+ const t = checkPropertyAccessExpressionOrQualifiedName(
1497
+ c,
1498
+ node,
1499
+ node.expression,
1500
+ checkNonNullType(c, nonOptional, node.expression),
1501
+ node.name,
1502
+ writeOnly,
1503
+ checkMode,
1504
+ );
1505
+ return propagateOptionalTypeMarker(c, t, node, nonOptional !== leftType);
1506
+ }
1507
+
1508
+ export function checkQualifiedName(c: Checker, node: QualifiedName): Type {
1509
+ const leftType = checkNonNullExpressionOfEntity(c, node.left);
1510
+ return checkPropertyAccessExpressionOrQualifiedName(c, node, node.left, leftType, node.right, false);
1511
+ }
1512
+
1513
+ function checkNonNullExpressionOfEntity(c: Checker, node: Node): Type {
1514
+ if (node.kind === SyntaxKind.Identifier) return checkNonNullType(c, checkIdentifier(c, node as Identifier), node);
1515
+ return checkNonNullType(c, checkQualifiedName(c, node as QualifiedName), node);
1516
+ }
1517
+
1518
+ export function getFlowTypeOfAccessExpression(
1519
+ c: Checker,
1520
+ node: Node,
1521
+ prop: Symbol | undefined,
1522
+ propTypeIn: Type,
1523
+ errorNode: Node,
1524
+ checkMode: CheckMode = CheckMode.Normal,
1525
+ ): Type {
1526
+ let propType = propTypeIn;
1527
+ const assignmentKind = getAssignmentTargetKind(node);
1528
+ if (assignmentKind === AssignmentKind.Definite)
1529
+ return removeMissingType(c, propType, prop !== undefined && (prop.flags & SymbolFlags.Optional) !== 0);
1530
+ if (
1531
+ prop !== undefined &&
1532
+ (prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) === 0 &&
1533
+ !((prop.flags & SymbolFlags.Method) !== 0 && (propType.flags & TypeFlags.Union) !== 0)
1534
+ )
1535
+ return propType;
1536
+ if (propType === c.autoType) return getFlowTypeOfAutoTypedProperty(c, node, prop);
1537
+ propType = getNarrowableTypeForReference(c, propType, node, checkMode);
1538
+ // `this.x` in the constructor of x's class starts out uninitialized under strictPropertyInitialization.
1539
+ let assumeUninitialized = false;
1540
+ const expression = getExpression(node);
1541
+ if (
1542
+ c.strictNullChecks &&
1543
+ c.strictPropertyInitialization &&
1544
+ expression !== undefined &&
1545
+ expression.kind === SyntaxKind.ThisKeyword &&
1546
+ prop !== undefined
1547
+ ) {
1548
+ const declaration = prop.valueDeclaration;
1549
+ if (declaration !== undefined && isPropertyWithoutInitializer(declaration) && !isStatic(declaration)) {
1550
+ const flowContainer = getControlFlowContainer(node);
1551
+ assumeUninitialized =
1552
+ flowContainer.kind === SyntaxKind.Constructor &&
1553
+ flowContainer.parent === declaration.parent &&
1554
+ (declaration.flags & NodeFlags.Ambient) === 0;
1555
+ }
1556
+ }
1557
+ // A JavaScript `this.x = …` declaration is unassigned before it in its own function.
1558
+ if (c.strictNullChecks && prop !== undefined && !assumeUninitialized) {
1559
+ const declaration = prop.valueDeclaration;
1560
+ assumeUninitialized =
1561
+ declaration instanceof BinaryExpression &&
1562
+ declaration.left.kind === SyntaxKind.PropertyAccessExpression &&
1563
+ getControlFlowContainer(node) === getControlFlowContainer(declaration);
1564
+ }
1565
+ const initialType = assumeUninitialized ? getOptionalType(c, propType, false) : propType;
1566
+ const flowType = getFlowTypeOfReference(c, node, propType, initialType, undefined);
1567
+ if (assumeUninitialized && !containsUndefinedType(propType) && containsUndefinedType(flowType)) {
1568
+ c.error(errorNode, Diagnostics.Property_0_is_used_before_being_assigned, symbolToString(c, prop!));
1569
+ return propType;
1570
+ }
1571
+ return assignmentKind !== AssignmentKind.None ? getBaseTypeOfLiteralType(c, flowType) : flowType;
1572
+ }
1573
+
1574
+ function isPropertyWithoutInitializer(node: Node): boolean {
1575
+ return (
1576
+ node.kind === SyntaxKind.PropertyDeclaration &&
1577
+ !hasSyntacticModifier(node, ModifierFlags.Abstract) &&
1578
+ (node as PropertyDeclaration).postfixToken === undefined &&
1579
+ getInitializer(node) === undefined
1580
+ );
1581
+ }
1582
+
1583
+ function checkElementAccessExpression(c: Checker, node: ElementAccessExpression, _checkMode: CheckMode): Type {
1584
+ let exprType = checkExpression(c, node.expression);
1585
+ let wasOptional = false;
1586
+ if (isOptionalChain(node)) {
1587
+ const nonOptional = getOptionalExpressionType(c, exprType, node.expression);
1588
+ wasOptional = nonOptional !== exprType;
1589
+ exprType = checkNonNullType(c, nonOptional, node.expression);
1590
+ } else exprType = checkNonNullType(c, exprType, node.expression);
1591
+ const indexExpression = node.argumentExpression;
1592
+ const indexType = checkExpression(c, indexExpression);
1593
+ if (isErrorType(c, exprType) || exprType === c.silentNeverType) return exprType;
1594
+ const assignmentKind = getAssignmentTargetKind(node);
1595
+ const isAssignment = assignmentKind !== AssignmentKind.None;
1596
+ const objectType = isAssignment || isMethodAccessForCall(node) ? getWidenedType(c, exprType) : exprType;
1597
+ if (isConstEnumObjectTypeLocal(objectType) && !isStringLiteralLike(indexExpression)) {
1598
+ c.error(indexExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
1599
+ return c.errorType;
1600
+ }
1601
+ const effectiveIndexType = isForInVariableForNumericPropertyNames(c, indexExpression) ? c.numberType : indexType;
1602
+ // A compound assignment (`a[i] += 1`, `a[i]++`) also reads the element.
1603
+ const accessFlags = isAssignment
1604
+ ? AccessFlags.Writing |
1605
+ (assignmentKind === AssignmentKind.Compound ? AccessFlags.ExpressionPosition : 0) |
1606
+ (isGenericObjectType(c, objectType) && !isThisTypeParameter(objectType) ? AccessFlags.NoIndexSignatures : 0)
1607
+ : AccessFlags.ExpressionPosition;
1608
+ const indexedAccessType =
1609
+ getIndexedAccessTypeOrUndefinedEx(c, objectType, effectiveIndexType, accessFlags, node, undefined) ?? c.errorType;
1610
+ const t = checkIndexedAccessIndexType(
1611
+ c,
1612
+ getFlowTypeOfAccessExpression(c, node, c.resolvedSymbols.get(node.id), indexedAccessType, indexExpression),
1613
+ node,
1614
+ );
1615
+ return propagateOptionalTypeMarker(c, t, node, wasOptional);
1616
+ }
1617
+
1618
+ /** Checks that the index of a generic indexed access is assignable to `keyof` its object type. */
1619
+ export function checkIndexedAccessIndexType(c: Checker, t: Type, accessNode: Node): Type {
1620
+ if ((t.flags & TypeFlags.IndexedAccess) === 0) return t;
1621
+ const objectType = (t as IndexedAccessType).objectType;
1622
+ const indexType = (t as IndexedAccessType).indexType;
1623
+ // Remapping mapped types don't defer their index types.
1624
+ const objectIndexType =
1625
+ isGenericMappedType(c, objectType) &&
1626
+ getMappedTypeNameTypeKind(c, objectType as MappedType) === MappedTypeNameTypeKind.Remapping
1627
+ ? getIndexForMappedType(c, objectType as MappedType, IndexFlags.None)
1628
+ : getIndexTypeEx(c, objectType, IndexFlags.None);
1629
+ const hasNumberIndexInfo = getIndexInfoOfType(c, objectType, c.numberType) !== undefined;
1630
+ if (
1631
+ everyType(
1632
+ indexType,
1633
+ (u) =>
1634
+ isTypeAssignableTo(c, u, objectIndexType) || (hasNumberIndexInfo && isApplicableIndexType(c, u, c.numberType)),
1635
+ )
1636
+ ) {
1637
+ if (
1638
+ accessNode.kind === SyntaxKind.ElementAccessExpression &&
1639
+ isAssignmentTarget(accessNode) &&
1640
+ (objectType.objectFlags & ObjectFlags.Mapped) !== 0 &&
1641
+ (getMappedTypeModifiers(objectType as MappedType) & MappedTypeModifiers.IncludeReadonly) !== 0
1642
+ )
1643
+ c.error(accessNode, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(c, objectType));
1644
+ return t;
1645
+ }
1646
+ if (isGenericObjectType(c, objectType)) {
1647
+ const propertyName = getPropertyNameFromIndex(indexType);
1648
+ if (propertyName !== undefined) {
1649
+ const propertySymbol = getConstituentProperty(c, objectType, propertyName);
1650
+ if (
1651
+ propertySymbol !== undefined &&
1652
+ (getDeclarationModifierFlagsFromSymbol(c, propertySymbol, false) &
1653
+ ModifierFlags.NonPublicAccessibilityModifier) !==
1654
+ 0
1655
+ ) {
1656
+ c.error(
1657
+ accessNode,
1658
+ Diagnostics.Private_or_protected_member_0_cannot_be_accessed_on_a_type_parameter,
1659
+ propertyName,
1660
+ );
1661
+ return c.errorType;
1662
+ }
1663
+ }
1664
+ }
1665
+ c.error(
1666
+ accessNode,
1667
+ Diagnostics.Type_0_cannot_be_used_to_index_type_1,
1668
+ typeToString(c, indexType),
1669
+ typeToString(c, objectType),
1670
+ );
1671
+ return c.errorType;
1672
+ }
1673
+
1674
+ function getConstituentProperty(c: Checker, objectType: Type, propertyName: string): Symbol | undefined {
1675
+ const apparentType = getApparentType(c, objectType);
1676
+ const constituents =
1677
+ (apparentType.flags & TypeFlags.UnionOrIntersection) !== 0 ? typesOf(apparentType) : [apparentType];
1678
+ for (const t of constituents) {
1679
+ const prop = getPropertyOfType(c, t, propertyName);
1680
+ if (prop !== undefined) return prop;
1681
+ }
1682
+ return undefined;
1683
+ }
1684
+
1685
+ function isStringLiteralLike(node: Node): boolean {
1686
+ return node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral;
1687
+ }
1688
+
1689
+ function isConstEnumObjectTypeLocal(t: Type): boolean {
1690
+ return (
1691
+ (t.objectFlags & ObjectFlags.Anonymous) !== 0 &&
1692
+ t.symbol !== undefined &&
1693
+ (t.symbol.flags & SymbolFlags.ConstEnum) !== 0
1694
+ );
1695
+ }
1696
+
1697
+ function isThisTypeParameter(t: Type): boolean {
1698
+ return (t.flags & TypeFlags.TypeParameter) !== 0 && (t as TypeParameter).isThisType;
1699
+ }
1700
+
1701
+ function isForInVariableForNumericPropertyNames(c: Checker, expr: Node): boolean {
1702
+ const e = skipParentheses(expr);
1703
+ if (e.kind !== SyntaxKind.Identifier) return false;
1704
+ const symbol = getResolvedSymbol(c, e);
1705
+ if ((symbol.flags & SymbolFlags.Variable) === 0) return false;
1706
+ let child = expr;
1707
+ let node = expr.parent;
1708
+ while (node !== undefined) {
1709
+ if (node.kind === SyntaxKind.ForInStatement) {
1710
+ const statement = node as ForInOrOfStatement;
1711
+ if (
1712
+ child === statement.statement &&
1713
+ getForInVariableSymbol(c, statement) === symbol &&
1714
+ hasNumericPropertyNames(c, getTypeOfExpression(c, statement.expression))
1715
+ )
1716
+ return true;
1717
+ }
1718
+ child = node;
1719
+ node = node.parent;
1720
+ }
1721
+ return false;
1722
+ }
1723
+
1724
+ function getForInVariableSymbol(c: Checker, node: ForInOrOfStatement): Symbol | undefined {
1725
+ const initializer = node.initializer;
1726
+ if (initializer.kind === SyntaxKind.VariableDeclarationList) {
1727
+ const declarations = (initializer as VariableDeclarationList).declarations.nodes;
1728
+ return declarations.length > 0 ? getSymbolOfDeclaration(c, declarations[0]!) : undefined;
1729
+ }
1730
+ return initializer.kind === SyntaxKind.Identifier ? getResolvedSymbol(c, initializer) : undefined;
1731
+ }
1732
+
1733
+ function hasNumericPropertyNames(c: Checker, t: Type): boolean {
1734
+ return getIndexInfosOfType(c, t).length === 1 && getIndexInfoOfType(c, t, c.numberType) !== undefined;
1735
+ }
1736
+
1737
+ // ---- Assertions
1738
+
1739
+ function checkAssertion(c: Checker, node: Node, checkMode: CheckMode): Type {
1740
+ // `<T>expr`, over `<T>`.
1741
+ if (node.kind === SyntaxKind.TypeAssertionExpression && shouldCheckErasableSyntax(c, node)) {
1742
+ const file = getSourceFileOfNode(node);
1743
+ c.addDiagnostic(
1744
+ new Diagnostic(
1745
+ file.diagnosticFile(),
1746
+ skipTrivia(file.text, node.pos),
1747
+ getExpression(node)!.pos,
1748
+ Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled,
1749
+ [],
1750
+ ),
1751
+ );
1752
+ }
1753
+ if (isConstTypeReference(getType(node)!)) {
1754
+ const exprType = checkExpressionEx(c, getExpression(node)!, checkMode);
1755
+ if (!isValidConstAssertionArgument(c, getExpression(node)!))
1756
+ c.error(
1757
+ getExpression(node)!,
1758
+ Diagnostics.A_const_assertion_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals,
1759
+ );
1760
+ return getRegularTypeOfLiteralType(c, exprType);
1761
+ }
1762
+ const exprType = checkExpressionEx(c, getExpression(node)!, checkMode);
1763
+ // The operand is compared with the asserted type once, after the last check of the operand.
1764
+ c.nodeLinks(node).assertionExpressionType = exprType;
1765
+ checkTypeNodeIfPresent(c, getType(node));
1766
+ checkNodeDeferred(c, node);
1767
+ return getTypeFromTypeNode(c, getType(node)!);
1768
+ }
1769
+
1770
+ /** Checks that an assertion's operand type and asserted type are comparable. */
1771
+ export function checkAssertionDeferred(c: Checker, node: Node): void {
1772
+ const typeNode = getType(node)!;
1773
+ const targetType = getTypeFromTypeNode(c, typeNode);
1774
+ // A JSDoc cast reports on its type.
1775
+ const errorNode = (typeNode.flags & NodeFlags.Reparsed) !== 0 ? typeNode : node;
1776
+ if (!isErrorType(c, targetType))
1777
+ checkAssertionCompatibility(c, errorNode, c.nodeLinks(node).assertionExpressionType!, targetType);
1778
+ }
1779
+
1780
+ function checkAssertionCompatibility(c: Checker, node: Node, rawExprType: Type, targetType: Type): void {
1781
+ const exprType = getRegularTypeOfObjectLiteral(c, getBaseTypeOfLiteralType(c, rawExprType));
1782
+ if (isErrorType(c, targetType)) return;
1783
+ if (!isTypeComparableTo(c, targetType, getWidenedType(c, exprType)))
1784
+ checkTypeComparableTo(
1785
+ c,
1786
+ exprType,
1787
+ targetType,
1788
+ node,
1789
+ Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first,
1790
+ );
1791
+ }
1792
+
1793
+ function checkSatisfiesExpression(c: Checker, node: Node, checkMode: CheckMode): Type {
1794
+ const expr = getExpression(node)!;
1795
+ const typeNode = getType(node)!;
1796
+ checkTypeNodeIfPresent(c, typeNode);
1797
+ const exprType = checkExpressionEx(c, expr, checkMode);
1798
+ const targetType = getTypeFromTypeNode(c, typeNode);
1799
+ if (isErrorType(c, targetType)) return targetType;
1800
+ checkTypeRelatedToAndOptionallyElaborate(
1801
+ c,
1802
+ exprType,
1803
+ targetType,
1804
+ c.assignableRelation,
1805
+ node,
1806
+ expr,
1807
+ Diagnostics.Type_0_does_not_satisfy_the_expected_type_1,
1808
+ undefined,
1809
+ );
1810
+ return exprType;
1811
+ }
1812
+
1813
+ /** Reports `source` not assignable to `target` at `errorNode`. */
1814
+ export function checkTypeAssignableToAndOptionallyElaborate(
1815
+ c: Checker,
1816
+ source: Type,
1817
+ target: Type,
1818
+ errorNode: Node,
1819
+ expr: Node | undefined,
1820
+ ): boolean {
1821
+ return checkTypeRelatedToAndOptionallyElaborate(
1822
+ c,
1823
+ source,
1824
+ target,
1825
+ c.assignableRelation,
1826
+ errorNode,
1827
+ expr,
1828
+ undefined,
1829
+ undefined,
1830
+ );
1831
+ }