tsc-ts 0.0.3 → 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 (596) hide show
  1. package/README.md +46 -0
  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 +74 -0
  357. package/dist/api/library/ast.generated.d.ts +1145 -0
  358. package/dist/api/library/ast.generated.js +3 -0
  359. package/dist/api/library/ast.js +5 -0
  360. package/dist/api/library/checker.d.ts +51 -0
  361. package/dist/api/library/checker.js +318 -0
  362. package/dist/api/library/compiler-options.generated.d.ts +108 -0
  363. package/dist/api/library/compiler-options.generated.js +3 -0
  364. package/dist/api/library/diagnostics.d.ts +13 -0
  365. package/dist/api/library/diagnostics.js +50 -0
  366. package/dist/api/library/disk.d.ts +13 -0
  367. package/dist/api/library/disk.js +66 -0
  368. package/dist/api/library/enums.generated.d.ts +891 -0
  369. package/dist/api/library/enums.generated.js +916 -0
  370. package/dist/api/library/errors.d.ts +13 -0
  371. package/dist/api/library/errors.js +24 -0
  372. package/dist/api/library/host.d.ts +24 -0
  373. package/dist/api/library/host.js +52 -0
  374. package/dist/api/library/index.d.ts +14 -0
  375. package/dist/api/library/index.js +15 -0
  376. package/dist/api/library/nodes.d.ts +51 -0
  377. package/dist/api/library/nodes.js +196 -0
  378. package/dist/api/library/options.d.ts +144 -0
  379. package/dist/api/library/options.js +308 -0
  380. package/dist/api/library/parse.d.ts +19 -0
  381. package/dist/api/library/parse.js +41 -0
  382. package/dist/api/library/program.d.ts +21 -0
  383. package/dist/api/library/program.js +234 -0
  384. package/dist/api/library/symbols.d.ts +8 -0
  385. package/dist/api/library/symbols.js +11 -0
  386. package/dist/api/library/types.d.ts +313 -0
  387. package/dist/api/library/types.js +6 -0
  388. package/package.json +22 -8
  389. package/src/compiler/ast-utilities.ts +548 -0
  390. package/src/compiler/ast.ts +12862 -0
  391. package/src/compiler/astnav.ts +799 -0
  392. package/src/compiler/binder-utilities.ts +1392 -0
  393. package/src/compiler/binder.ts +2703 -0
  394. package/src/compiler/build-info.ts +1197 -0
  395. package/src/compiler/character-codes.ts +323 -0
  396. package/src/compiler/checker-calls.ts +2155 -0
  397. package/src/compiler/checker-classes.ts +706 -0
  398. package/src/compiler/checker-contextual.ts +1457 -0
  399. package/src/compiler/checker-declaration-order.ts +438 -0
  400. package/src/compiler/checker-declarations.ts +1194 -0
  401. package/src/compiler/checker-declared-types.ts +919 -0
  402. package/src/compiler/checker-decorators.ts +694 -0
  403. package/src/compiler/checker-deprecation.ts +359 -0
  404. package/src/compiler/checker-destructuring.ts +805 -0
  405. package/src/compiler/checker-elaboration.ts +477 -0
  406. package/src/compiler/checker-emit-helpers.ts +224 -0
  407. package/src/compiler/checker-emit-resolver.ts +769 -0
  408. package/src/compiler/checker-evaluator.ts +243 -0
  409. package/src/compiler/checker-expressions.ts +1831 -0
  410. package/src/compiler/checker-features.ts +361 -0
  411. package/src/compiler/checker-flow.ts +394 -0
  412. package/src/compiler/checker-functions.ts +1296 -0
  413. package/src/compiler/checker-generated-code.ts +227 -0
  414. package/src/compiler/checker-globals.ts +52 -0
  415. package/src/compiler/checker-grammar.ts +3584 -0
  416. package/src/compiler/checker-heritage.ts +1233 -0
  417. package/src/compiler/checker-inference.ts +2576 -0
  418. package/src/compiler/checker-iteration.ts +1206 -0
  419. package/src/compiler/checker-javascript.ts +502 -0
  420. package/src/compiler/checker-jsdoc.ts +360 -0
  421. package/src/compiler/checker-jsx.ts +1924 -0
  422. package/src/compiler/checker-literals.ts +61 -0
  423. package/src/compiler/checker-members.ts +2436 -0
  424. package/src/compiler/checker-modules.ts +2886 -0
  425. package/src/compiler/checker-narrowing.ts +3230 -0
  426. package/src/compiler/checker-object-literals.ts +575 -0
  427. package/src/compiler/checker-operators.ts +1422 -0
  428. package/src/compiler/checker-overloads.ts +328 -0
  429. package/src/compiler/checker-property-access.ts +906 -0
  430. package/src/compiler/checker-services.ts +1149 -0
  431. package/src/compiler/checker-signatures.ts +1032 -0
  432. package/src/compiler/checker-source-file.ts +732 -0
  433. package/src/compiler/checker-statements.ts +292 -0
  434. package/src/compiler/checker-super.ts +261 -0
  435. package/src/compiler/checker-symbol-types.ts +2107 -0
  436. package/src/compiler/checker-symbols.ts +2150 -0
  437. package/src/compiler/checker-type-factory.ts +2579 -0
  438. package/src/compiler/checker-type-nodes.ts +1033 -0
  439. package/src/compiler/checker-type-operators.ts +2502 -0
  440. package/src/compiler/checker-types.ts +2340 -0
  441. package/src/compiler/checker-unused.ts +642 -0
  442. package/src/compiler/checker-utilities.ts +161 -0
  443. package/src/compiler/checker.ts +1116 -0
  444. package/src/compiler/command-line.ts +436 -0
  445. package/src/compiler/compile-program.ts +439 -0
  446. package/src/compiler/decoder.ts +1209 -0
  447. package/src/compiler/diagnostic-locales.ts +86 -0
  448. package/src/compiler/diagnostic-messages.ts +2349 -0
  449. package/src/compiler/diagnostics.ts +897 -0
  450. package/src/compiler/emitter.ts +434 -0
  451. package/src/compiler/encoder.ts +1945 -0
  452. package/src/compiler/file-include.ts +673 -0
  453. package/src/compiler/file-loader.ts +1528 -0
  454. package/src/compiler/file-system.ts +143 -0
  455. package/src/compiler/flow.ts +89 -0
  456. package/src/compiler/help.ts +473 -0
  457. package/src/compiler/incremental.ts +2784 -0
  458. package/src/compiler/init.ts +141 -0
  459. package/src/compiler/instantiation.ts +894 -0
  460. package/src/compiler/jsdoc.ts +1386 -0
  461. package/src/compiler/link-tables.ts +98 -0
  462. package/src/compiler/locale-data.ts +203 -0
  463. package/src/compiler/locale.ts +307 -0
  464. package/src/compiler/locales/cs-CZ.ts +5 -0
  465. package/src/compiler/locales/de-DE.ts +5 -0
  466. package/src/compiler/locales/es-ES.ts +5 -0
  467. package/src/compiler/locales/fr-FR.ts +5 -0
  468. package/src/compiler/locales/it-IT.ts +5 -0
  469. package/src/compiler/locales/ja-JP.ts +5 -0
  470. package/src/compiler/locales/ko-KR.ts +5 -0
  471. package/src/compiler/locales/pl-PL.ts +5 -0
  472. package/src/compiler/locales/pt-BR.ts +5 -0
  473. package/src/compiler/locales/ru-RU.ts +5 -0
  474. package/src/compiler/locales/tr-TR.ts +5 -0
  475. package/src/compiler/locales/zh-CN.ts +5 -0
  476. package/src/compiler/locales/zh-TW.ts +5 -0
  477. package/src/compiler/module-resolution-types.ts +243 -0
  478. package/src/compiler/module-resolution.ts +2072 -0
  479. package/src/compiler/module-specifiers.ts +1491 -0
  480. package/src/compiler/name-resolver.ts +646 -0
  481. package/src/compiler/node-builder-names.ts +1069 -0
  482. package/src/compiler/node-builder-pseudo.ts +892 -0
  483. package/src/compiler/node-builder-reuse.ts +764 -0
  484. package/src/compiler/node-builder.ts +3425 -0
  485. package/src/compiler/option-declarations.ts +1560 -0
  486. package/src/compiler/options.ts +1576 -0
  487. package/src/compiler/output-paths.ts +334 -0
  488. package/src/compiler/package-json.ts +1083 -0
  489. package/src/compiler/parallel-check.ts +1951 -0
  490. package/src/compiler/parallel-parse.ts +590 -0
  491. package/src/compiler/parse-thread.ts +140 -0
  492. package/src/compiler/parser.ts +7716 -0
  493. package/src/compiler/path.ts +717 -0
  494. package/src/compiler/printer/async-helpers.ts +183 -0
  495. package/src/compiler/printer/auto-generate.ts +27 -0
  496. package/src/compiler/printer/decorator-helpers.ts +218 -0
  497. package/src/compiler/printer/emit-context.ts +679 -0
  498. package/src/compiler/printer/emit-flags.ts +64 -0
  499. package/src/compiler/printer/factory-base.ts +2577 -0
  500. package/src/compiler/printer/factory.ts +764 -0
  501. package/src/compiler/printer/helpers.ts +291 -0
  502. package/src/compiler/printer/name-generator.ts +372 -0
  503. package/src/compiler/printer/printer.ts +5072 -0
  504. package/src/compiler/printer/text-writer.ts +183 -0
  505. package/src/compiler/printer/utilities.ts +884 -0
  506. package/src/compiler/program-checker.ts +592 -0
  507. package/src/compiler/program-utilities.ts +435 -0
  508. package/src/compiler/program.ts +1419 -0
  509. package/src/compiler/pseudo-bigint.ts +62 -0
  510. package/src/compiler/regexp-checker.ts +1142 -0
  511. package/src/compiler/relations.ts +5149 -0
  512. package/src/compiler/reparser.ts +1566 -0
  513. package/src/compiler/scanner.ts +2951 -0
  514. package/src/compiler/show-config.ts +239 -0
  515. package/src/compiler/side-state.ts +125 -0
  516. package/src/compiler/sourcemap.ts +366 -0
  517. package/src/compiler/spelling.ts +122 -0
  518. package/src/compiler/symbol-accessibility.ts +1071 -0
  519. package/src/compiler/symbol.ts +439 -0
  520. package/src/compiler/symlinks.ts +137 -0
  521. package/src/compiler/syntax-kind.ts +391 -0
  522. package/src/compiler/thread-entry.ts +191 -0
  523. package/src/compiler/timeline.ts +53 -0
  524. package/src/compiler/transformers/alias-references.ts +757 -0
  525. package/src/compiler/transformers/async-utilities.ts +335 -0
  526. package/src/compiler/transformers/async.ts +838 -0
  527. package/src/compiler/transformers/class-fields.ts +2967 -0
  528. package/src/compiler/transformers/class-utilities.ts +324 -0
  529. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  530. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  531. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  532. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  533. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  534. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  535. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  536. package/src/compiler/transformers/declarations.ts +3120 -0
  537. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  538. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  539. package/src/compiler/transformers/destructuring.ts +708 -0
  540. package/src/compiler/transformers/downlevel.ts +50 -0
  541. package/src/compiler/transformers/emit-resolver.ts +258 -0
  542. package/src/compiler/transformers/es-decorators.ts +2682 -0
  543. package/src/compiler/transformers/exponentiation.ts +80 -0
  544. package/src/compiler/transformers/external-module-info.ts +412 -0
  545. package/src/compiler/transformers/for-await.ts +687 -0
  546. package/src/compiler/transformers/import-elision.ts +152 -0
  547. package/src/compiler/transformers/jsx-entities.ts +256 -0
  548. package/src/compiler/transformers/jsx.ts +824 -0
  549. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  550. package/src/compiler/transformers/logical-assignment.ts +75 -0
  551. package/src/compiler/transformers/module-utilities.ts +42 -0
  552. package/src/compiler/transformers/module.ts +474 -0
  553. package/src/compiler/transformers/named-evaluation.ts +389 -0
  554. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  555. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  556. package/src/compiler/transformers/optional-catch.ts +29 -0
  557. package/src/compiler/transformers/optional-chain.ts +246 -0
  558. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  559. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  560. package/src/compiler/transformers/subtree-facts.ts +245 -0
  561. package/src/compiler/transformers/syntax-facts.ts +353 -0
  562. package/src/compiler/transformers/tagged-template.ts +167 -0
  563. package/src/compiler/transformers/transformer.ts +56 -0
  564. package/src/compiler/transformers/type-eraser.ts +520 -0
  565. package/src/compiler/transformers/type-serialization.ts +374 -0
  566. package/src/compiler/transformers/using.ts +613 -0
  567. package/src/compiler/transformers/utilities.ts +419 -0
  568. package/src/compiler/transformers/visitor-base.ts +1601 -0
  569. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  570. package/src/compiler/tsc-build.ts +1418 -0
  571. package/src/compiler/tsc-cli.ts +666 -0
  572. package/src/compiler/tsc-compile.ts +437 -0
  573. package/src/compiler/tsc-watch.ts +854 -0
  574. package/src/compiler/tsconfig.ts +1574 -0
  575. package/src/compiler/type-printer.ts +110 -0
  576. package/src/compiler/types.ts +115 -0
  577. package/src/compiler/unicode-identifiers.ts +212 -0
  578. package/src/compiler/unicode-properties.ts +537 -0
  579. package/src/compiler/vfs-match.ts +597 -0
  580. package/src/compiler/xxh3.ts +650 -0
  581. package/src/library/ast.generated.ts +1685 -0
  582. package/src/library/ast.ts +104 -0
  583. package/src/library/checker.ts +384 -0
  584. package/src/library/compiler-options.generated.ts +114 -0
  585. package/src/library/diagnostics.ts +72 -0
  586. package/src/library/disk.ts +73 -0
  587. package/src/library/enums.generated.ts +1024 -0
  588. package/src/library/errors.ts +26 -0
  589. package/src/library/host.ts +63 -0
  590. package/src/library/index.ts +71 -0
  591. package/src/library/nodes.ts +232 -0
  592. package/src/library/options.ts +449 -0
  593. package/src/library/parse.ts +63 -0
  594. package/src/library/program.ts +293 -0
  595. package/src/library/symbols.ts +15 -0
  596. package/src/library/types.ts +359 -0
@@ -0,0 +1,4002 @@
1
+ // Type relations: identity, subtype, strict subtype, assignability and comparability, with
2
+ // tsgo's result caching, recursion limits, variance measurement and error elaboration.
3
+ import { lazyObjectFlags, sideOf, sideOfIfAny } from './side-state.js';
4
+ import { getExpression, getName, getNodeId, getText, } from './ast.js';
5
+ import { getSymbolNameForPrivateIdentifier } from './binder.js';
6
+ import { getCombinedModifierFlags } from './binder-utilities.js';
7
+ import { Diagnostic, messageElidedInCompatibilityPyramid } from './diagnostics.js';
8
+ import { getSymbolId } from './symbol.js';
9
+ import { isContextSensitive } from './checker-functions.js';
10
+ import { createDiagnosticForNode } from './checker.js';
11
+ import { cachedTypeKey, emptyTypes, newTypeMapper, SimpleTypeMapper, } from './checker-types.js';
12
+ import { createInferenceContext, inferTypes } from './checker-inference.js';
13
+ import { unionContainsSortedTypes, unionContainsType, createArrayTypeEx, compareTypes, containsMissingType, createTypeReference, everyType, filterType, getBaseTypeOfLiteralType, getBaseTypeOfEnumLikeType, getElementTypes, getIntersectionType, getIntersectionTypeEx, getTargetType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, isArrayOrTupleType, isArrayType, isEmptyAnonymousObjectType, isEmptyObjectType, isErrorType, isFreshLiteralType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, isUnitType, someType, tupleTargetOf, typesOf, countTypes, getStartElementCount, getEndElementCount, createNormalizedTypeReference, typeListKey, getRegularTypeOfLiteralType, } from './checker-type-factory.js';
14
+ import { findApplicableIndexInfo, getApparentType, getApplicableIndexInfo, getApplicableIndexInfoForName, getBaseConstraintOfType, getBaseConstraintOrType, getConstraintOfType, getDeclarationModifierFlagsFromSymbol, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getPropertiesOfObjectType, getPropertiesOfType, getPropertiesOfUnionOrIntersectionType, getPropertyOfObjectType, getPropertyOfType, getPropertyOfUnionOrIntersectionType, getReducedType, getSignaturesOfStructuredType, getSignaturesOfType, getTargetSymbol, getTypeOfPropertyOfType, getTypeWithThisArgument, getUnionOrIntersectionProperty, isApplicableIndexType, isArrayLikeType, isObjectLiteralType, isDiscriminantWithNeverType, isConflictingPrivateProperty, resolveStructuredTypeMembers, getResolvedMember, hasResolvedProperties, resolvedPropertiesAreOptional, } from './checker-members.js';
15
+ import { getParentOfSymbol, getMergedSymbol, getMembersOfSymbol, getSpellingSuggestionForName, } from './checker-symbols.js';
16
+ import { CodePoints, distanceToCandidate, utf8Length } from './spelling.js';
17
+ import { getConstraintFromTypeParameter, getDeclaredTypeOfSymbol, getDefaultOrUnknownFromTypeParameter, fillMissingTypeArguments, getMinTypeArgumentCount, hasBaseType, hasNonCircularBaseConstraint, computeEnumMemberValues, getBaseTypes, getExtendsHeritageClauseElement, } from './checker-declared-types.js';
18
+ import { getNonMissingTypeOfSymbol, getOptionalType, getTypeOfSymbol, isReadonlySymbol, removeMissingType, addOptionality, } from './checker-symbol-types.js';
19
+ import { cloneTypeParameter, couldContainTypeVariables, instantiateSignatureEx, instantiateType, isTypeParameterPossiblyReferenced, getRestrictiveInstantiation, } from './instantiation.js';
20
+ import { getJsxType, getSuggestedSymbolForNonexistentJSXAttribute, isJsxOpeningLikeElement } from './checker-jsx.js';
21
+ import { signatureToString, symbolToString, typeToString, typePredicateToString } from './type-printer.js';
22
+ import { getConstraintOfDistributiveConditionalType, getDefaultConstraintOfConditionalType, getConstraintTypeFromMappedType, getFalseTypeFromConditionalType, getIndexType, getIndexTypeEx, getIndexedAccessType, getIndexedAccessTypeOrUndefined, getMappedTypeModifiers, getCombinedMappedTypeOptionality, getModifiersTypeFromMappedType, getNameTypeFromMappedType, getPermissiveInstantiation, getSimplifiedType, getSubstitutionIntersection, getTemplateTypeFromMappedType, getTrueTypeFromConditionalType, getTypeParameterFromMappedType, isGenericIndexType, isGenericMappedType, isGenericObjectType, isMappedTypeGenericIndexedAccess, isTypeMatchedByTemplateLiteralType, isMemberOfStringMapping, getApparentMappedTypeKeys, shouldDeferIndexType, isMappedTypeWithKeyofConstraintDeclaration, } from './checker-type-operators.js';
23
+ import { getCanonicalSignature, getErasedSignature, getMinArgumentCount, getNonArrayRestType, getNonCircularReturnTypeOfSignature, getParameterCount, getParameterNameAtPosition, getRestOrAnyTypeAtPosition, getReturnTypeOfSignature, getSingleCallSignature, getThisTypeOfSignature, getTypeAtPosition, getTypePredicateOfSignature, hasEffectiveRestParameter, instantiateSignatureInContextOf, isTopSignature, tryGetTypeAtPosition, } from './checker-signatures.js';
24
+ import { getNonNullableType, getTypeFacts } from './checker-flow.js';
25
+ import { getPropertyNameFromType, isLateBoundName, isNumericLiteralName, maybeTypeOfKind, } from './checker-utilities.js';
26
+ /**
27
+ * Cached results of one relation by numeric relation key (see getRelationKey): an open-addressing
28
+ * table of keys and one-byte results. Keys are never 0 (packed keys are positive, interned ones
29
+ * negative), so 0 marks a free slot. At 3/8 to 3/4 full it takes about 16 bytes per result, where a
30
+ * Map takes about 40 (a 24-byte entry, its share of the bucket table and of the spare capacity);
31
+ * relations are most of a checker's tables on programs with many structural comparisons.
32
+ */
33
+ export class Relation {
34
+ keys = new Float64Array(64);
35
+ results = new Uint8Array(64);
36
+ count = 0;
37
+ get(key) {
38
+ const keys = this.keys;
39
+ const mask = keys.length - 1;
40
+ for (let i = relationSlot(key) & mask;; i = (i + 1) & mask) {
41
+ const k = keys[i];
42
+ if (k === key)
43
+ return this.results[i];
44
+ if (k === 0)
45
+ return 0 /* RelationComparisonResult.None */;
46
+ }
47
+ }
48
+ set(key, result) {
49
+ const keys = this.keys;
50
+ const mask = keys.length - 1;
51
+ for (let i = relationSlot(key) & mask;; i = (i + 1) & mask) {
52
+ const k = keys[i];
53
+ if (k === key) {
54
+ this.results[i] = result;
55
+ return;
56
+ }
57
+ if (k === 0) {
58
+ keys[i] = key;
59
+ this.results[i] = result;
60
+ this.count++;
61
+ if (this.count * 4 > keys.length * 3)
62
+ this.grow();
63
+ return;
64
+ }
65
+ }
66
+ }
67
+ size() {
68
+ return this.count;
69
+ }
70
+ grow() {
71
+ const oldKeys = this.keys;
72
+ const oldResults = this.results;
73
+ const keys = new Float64Array(oldKeys.length * 2);
74
+ const results = new Uint8Array(oldKeys.length * 2);
75
+ const mask = keys.length - 1;
76
+ for (let j = 0; j < oldKeys.length; j++) {
77
+ const key = oldKeys[j];
78
+ if (key === 0)
79
+ continue;
80
+ let i = relationSlot(key) & mask;
81
+ while (keys[i] !== 0)
82
+ i = (i + 1) & mask;
83
+ keys[i] = key;
84
+ results[i] = oldResults[j];
85
+ }
86
+ this.keys = keys;
87
+ this.results = results;
88
+ }
89
+ }
90
+ /**
91
+ * The hash of a relation key, an integer of at most 53 bits: its low 24 bits (a type id in packed
92
+ * keys) mixed with the rest, both small enough for int32 arithmetic.
93
+ */
94
+ function relationSlot(key) {
95
+ const high = Math.floor(key / 16777216);
96
+ const low = key - high * 16777216;
97
+ const h = Math.imul((high | 0) ^ Math.imul(low | 0, 0x9e3779b1 | 0), 0x85ebca6b | 0);
98
+ return h ^ (h >>> 15);
99
+ }
100
+ // ---- Comparers
101
+ /**
102
+ * Compares types for signature and property comparisons, and receives their error reports.
103
+ * Subclasses replace tsgo's comparer and error reporter callbacks.
104
+ */
105
+ export class TypeComparer {
106
+ /** Records an elaboration; the default ignores it. */
107
+ report(_message, _args) { }
108
+ }
109
+ class RelationComparer extends TypeComparer {
110
+ c;
111
+ kind;
112
+ constructor(c, kind) {
113
+ super();
114
+ this.c = c;
115
+ this.kind = kind;
116
+ }
117
+ compare(source, target, _reportErrors) {
118
+ const c = this.c;
119
+ switch (this.kind) {
120
+ case 0 /* ComparerKind.Identical */:
121
+ return isTypeRelatedTo(c, source, target, c.identityRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
122
+ case 1 /* ComparerKind.SubtypeOf */:
123
+ return isTypeRelatedTo(c, source, target, c.subtypeRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
124
+ case 2 /* ComparerKind.Assignable */:
125
+ return isTypeRelatedTo(c, source, target, c.assignableRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
126
+ }
127
+ return source === target ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
128
+ }
129
+ }
130
+ export function getComparer(c, kind) {
131
+ let list = c.relationComparers;
132
+ if (list.length === 0) {
133
+ list = [
134
+ new RelationComparer(c, 0 /* ComparerKind.Identical */),
135
+ new RelationComparer(c, 1 /* ComparerKind.SubtypeOf */),
136
+ new RelationComparer(c, 2 /* ComparerKind.Assignable */),
137
+ new RelationComparer(c, 3 /* ComparerKind.Equal */),
138
+ ];
139
+ c.relationComparers = list;
140
+ }
141
+ return list[kind];
142
+ }
143
+ export function compareTypesIdentical(c, s, t) {
144
+ return isTypeRelatedTo(c, s, t, c.identityRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
145
+ }
146
+ export function compareTypesSubtypeOf(c, s, t) {
147
+ return isTypeRelatedTo(c, s, t, c.subtypeRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
148
+ }
149
+ export function compareTypesAssignable(c, s, t) {
150
+ return isTypeRelatedTo(c, s, t, c.assignableRelation) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
151
+ }
152
+ export function compareTypesEqual(_c, s, t) {
153
+ return s === t ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
154
+ }
155
+ // ---- Entry points
156
+ export function isTypeIdenticalTo(c, source, target) {
157
+ return isTypeRelatedTo(c, source, target, c.identityRelation);
158
+ }
159
+ export function isTypeAssignableTo(c, source, target) {
160
+ return isTypeRelatedTo(c, source, target, c.assignableRelation);
161
+ }
162
+ export function isTypeSubtypeOf(c, source, target) {
163
+ return isTypeRelatedTo(c, source, target, c.subtypeRelation);
164
+ }
165
+ export function isTypeStrictSubtypeOf(c, source, target) {
166
+ return isTypeRelatedTo(c, source, target, c.strictSubtypeRelation);
167
+ }
168
+ export function isTypeComparableTo(c, source, target) {
169
+ return isTypeRelatedTo(c, source, target, c.comparableRelation);
170
+ }
171
+ export function areTypesComparable(c, type1, type2) {
172
+ return isTypeComparableTo(c, type1, type2) || isTypeComparableTo(c, type2, type1);
173
+ }
174
+ export function isTypeRelatedTo(c, source, target, relation) {
175
+ if (isFreshLiteralType(source))
176
+ source = source.regularType;
177
+ if (isFreshLiteralType(target))
178
+ target = target.regularType;
179
+ if (source === target)
180
+ return true;
181
+ // A template literal target whose start and end texts rule out a match relates to no string
182
+ // literal or template literal source, under any relation. (The full check reports unreliable
183
+ // variance for type variables in a template literal source, so those take it.)
184
+ if ((target.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
185
+ if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 &&
186
+ !stringLiteralTextMayMatch(source.stringValue, target))
187
+ return false;
188
+ if ((source.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0 &&
189
+ (relation === c.comparableRelation
190
+ ? templateLiteralTypesDefinitelyUnrelated(source, target)
191
+ : !templateLiteralTextsMayMatch(source, target)) &&
192
+ !someTypeCouldContainTypeVariables(c, source.types))
193
+ return false;
194
+ }
195
+ if (relation !== c.identityRelation) {
196
+ if ((relation === c.comparableRelation &&
197
+ (target.flags & 262144 /* TypeFlags.Never */) === 0 &&
198
+ isSimpleTypeRelatedTo(c, target, source, relation, undefined)) ||
199
+ isSimpleTypeRelatedTo(c, source, target, relation, undefined))
200
+ return true;
201
+ // A primitive against a union: the relater (in typeRelatedToSomeType) finds it related when the
202
+ // union contains it, and decides a union of primitives without setting up a relater. Unions of
203
+ // four or more primitives that membership doesn't decide take the full check, which caches them.
204
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0 && (source.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) === 0) {
205
+ if (unionContainsType(c, target, source))
206
+ return true;
207
+ if ((target.objectFlags & 32768 /* ObjectFlags.PrimitiveUnion */) !== 0) {
208
+ if (isLiteralRelatedByPrimitiveUnionForms(c, source, target, relation))
209
+ return literalRelatedToPrimitiveUnion(c, source, target);
210
+ const types = typesOf(target);
211
+ if (types.length < 4) {
212
+ for (const t of types) {
213
+ const u = isFreshLiteralType(t) ? t.regularType : t;
214
+ if (source === u ||
215
+ (relation === c.comparableRelation &&
216
+ (u.flags & 262144 /* TypeFlags.Never */) === 0 &&
217
+ isSimpleTypeRelatedTo(c, u, source, relation, undefined)) ||
218
+ isSimpleTypeRelatedTo(c, source, u, relation, undefined))
219
+ return true;
220
+ }
221
+ return false;
222
+ }
223
+ }
224
+ }
225
+ }
226
+ else if (((source.flags | target.flags) &
227
+ (402653184 /* TypeFlags.UnionOrIntersection */ | 33554432 /* TypeFlags.IndexedAccess */ | 67108864 /* TypeFlags.Conditional */ | 16777216 /* TypeFlags.Substitution */)) ===
228
+ 0) {
229
+ // Types that can't simplify must have identical flags.
230
+ if (source.flags !== target.flags)
231
+ return false;
232
+ if ((source.flags & 394239 /* TypeFlags.Singleton */) !== 0)
233
+ return true;
234
+ }
235
+ if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 1048576 /* TypeFlags.Object */) !== 0) {
236
+ const related = relation.get(getRelationKey(c, source, target, 0 /* IntersectionState.None */, relation === c.identityRelation, false).key);
237
+ if (related !== 0 /* RelationComparisonResult.None */)
238
+ return (related & 1 /* RelationComparisonResult.Succeeded */) !== 0;
239
+ }
240
+ if ((source.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) !== 0 ||
241
+ (target.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) !== 0)
242
+ return checkTypeRelatedTo(c, source, target, relation, undefined, undefined, undefined);
243
+ return false;
244
+ }
245
+ /**
246
+ * Whether `source` is a literal that relates to the primitive union `target` only through its base
247
+ * primitive or its other freshness form (see literalRelatedToPrimitiveUnion).
248
+ */
249
+ function isLiteralRelatedByPrimitiveUnionForms(c, source, target, relation) {
250
+ return (relation !== c.comparableRelation &&
251
+ (target.objectFlags & 32768 /* ObjectFlags.PrimitiveUnion */) !== 0 &&
252
+ (source.flags & 32768 /* TypeFlags.EnumLiteral */) === 0 &&
253
+ ((source.flags & (1024 /* TypeFlags.StringLiteral */ | 8192 /* TypeFlags.BooleanLiteral */ | 4096 /* TypeFlags.BigIntLiteral */)) !== 0 ||
254
+ ((relation === c.subtypeRelation || relation === c.strictSubtypeRelation) &&
255
+ (source.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0)));
256
+ }
257
+ function literalRelatedToPrimitiveUnion(c, source, target) {
258
+ const literal = source;
259
+ // Typed: scriptc can't pass the narrowed LiteralType field as a Type.
260
+ const alternateForm = source === literal.regularType ? (literal.freshType ?? sideOfIfAny(c, literal)?.freshType) : literal.regularType;
261
+ let primitive;
262
+ if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0)
263
+ primitive = c.stringType;
264
+ else if ((source.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0)
265
+ primitive = c.numberType;
266
+ else if ((source.flags & 4096 /* TypeFlags.BigIntLiteral */) !== 0)
267
+ primitive = c.bigintType;
268
+ return ((primitive !== undefined && unionContainsType(c, target, primitive)) ||
269
+ (alternateForm !== undefined && unionContainsType(c, target, alternateForm)));
270
+ }
271
+ export function isSimpleTypeRelatedTo(c, source, target, relation, reporter) {
272
+ // Every rule below that can succeed needs one of these target flags, one of these source flags, or
273
+ // the wildcard source. Most pairs (objects, type parameters, intersections) have none of them; the
274
+ // test is small enough to inline into callers.
275
+ if ((target.flags &
276
+ (1 /* TypeFlags.Any */ |
277
+ 2 /* TypeFlags.Unknown */ |
278
+ 32 /* TypeFlags.String */ |
279
+ 1024 /* TypeFlags.StringLiteral */ |
280
+ 64 /* TypeFlags.Number */ |
281
+ 2048 /* TypeFlags.NumberLiteral */ |
282
+ 128 /* TypeFlags.BigInt */ |
283
+ 256 /* TypeFlags.Boolean */ |
284
+ 512 /* TypeFlags.ESSymbol */ |
285
+ 65536 /* TypeFlags.Enum */ |
286
+ 32768 /* TypeFlags.EnumLiteral */ |
287
+ 131072 /* TypeFlags.NonPrimitive */ |
288
+ 134217728 /* TypeFlags.Union */)) ===
289
+ 0 &&
290
+ (source.flags & (1 /* TypeFlags.Any */ | 262144 /* TypeFlags.Never */ | 4 /* TypeFlags.Undefined */ | 8 /* TypeFlags.Null */)) === 0 &&
291
+ source !== c.wildcardType)
292
+ return false;
293
+ return isSimpleTypeRelatedToWorker(c, source, target, relation, reporter);
294
+ }
295
+ function isSimpleTypeRelatedToWorker(c, source, target, relation, reporter) {
296
+ const s = source.flags;
297
+ const t = target.flags;
298
+ if ((t & 1 /* TypeFlags.Any */) !== 0 || (s & 262144 /* TypeFlags.Never */) !== 0 || source === c.wildcardType)
299
+ return true;
300
+ if ((t & 2 /* TypeFlags.Unknown */) !== 0 && !(relation === c.strictSubtypeRelation && (s & 1 /* TypeFlags.Any */) !== 0))
301
+ return true;
302
+ if ((t & 262144 /* TypeFlags.Never */) !== 0)
303
+ return false;
304
+ if ((s & 12583968 /* TypeFlags.StringLike */) !== 0 && (t & 32 /* TypeFlags.String */) !== 0)
305
+ return true;
306
+ if ((s & 1024 /* TypeFlags.StringLiteral */) !== 0 &&
307
+ (s & 32768 /* TypeFlags.EnumLiteral */) !== 0 &&
308
+ (t & 1024 /* TypeFlags.StringLiteral */) !== 0 &&
309
+ (t & 32768 /* TypeFlags.EnumLiteral */) === 0 &&
310
+ source.stringValue === target.stringValue)
311
+ return true;
312
+ if ((s & 67648 /* TypeFlags.NumberLike */) !== 0 && (t & 64 /* TypeFlags.Number */) !== 0)
313
+ return true;
314
+ if ((s & 2048 /* TypeFlags.NumberLiteral */) !== 0 &&
315
+ (s & 32768 /* TypeFlags.EnumLiteral */) !== 0 &&
316
+ (t & 2048 /* TypeFlags.NumberLiteral */) !== 0 &&
317
+ (t & 32768 /* TypeFlags.EnumLiteral */) === 0 &&
318
+ sameLiteralValue(source, target))
319
+ return true;
320
+ if ((s & 4224 /* TypeFlags.BigIntLike */) !== 0 && (t & 128 /* TypeFlags.BigInt */) !== 0)
321
+ return true;
322
+ if ((s & 8448 /* TypeFlags.BooleanLike */) !== 0 && (t & 256 /* TypeFlags.Boolean */) !== 0)
323
+ return true;
324
+ if ((s & 16896 /* TypeFlags.ESSymbolLike */) !== 0 && (t & 512 /* TypeFlags.ESSymbol */) !== 0)
325
+ return true;
326
+ if ((s & 65536 /* TypeFlags.Enum */) !== 0 &&
327
+ (t & 65536 /* TypeFlags.Enum */) !== 0 &&
328
+ source.symbol.name === target.symbol.name &&
329
+ isEnumTypeRelatedTo(c, source.symbol, target.symbol, reporter))
330
+ return true;
331
+ if ((s & 32768 /* TypeFlags.EnumLiteral */) !== 0 && (t & 32768 /* TypeFlags.EnumLiteral */) !== 0) {
332
+ if ((s & 134217728 /* TypeFlags.Union */) !== 0 &&
333
+ (t & 134217728 /* TypeFlags.Union */) !== 0 &&
334
+ isEnumTypeRelatedTo(c, source.symbol, target.symbol, reporter))
335
+ return true;
336
+ if ((s & 15360 /* TypeFlags.Literal */) !== 0 &&
337
+ (t & 15360 /* TypeFlags.Literal */) !== 0 &&
338
+ sameLiteralValue(source, target) &&
339
+ isEnumTypeRelatedTo(c, source.symbol, target.symbol, reporter))
340
+ return true;
341
+ }
342
+ // Without strictNullChecks, undefined and null are assignable to anything but never (and unions/intersections that may reduce to it).
343
+ if ((s & 4 /* TypeFlags.Undefined */) !== 0 &&
344
+ ((!c.strictNullChecks && (t & 402653184 /* TypeFlags.UnionOrIntersection */) === 0) ||
345
+ (t & (4 /* TypeFlags.Undefined */ | 16 /* TypeFlags.Void */)) !== 0))
346
+ return true;
347
+ if ((s & 8 /* TypeFlags.Null */) !== 0 &&
348
+ ((!c.strictNullChecks && (t & 402653184 /* TypeFlags.UnionOrIntersection */) === 0) || (t & 8 /* TypeFlags.Null */) !== 0))
349
+ return true;
350
+ if ((s & 1048576 /* TypeFlags.Object */) !== 0 &&
351
+ (t & 131072 /* TypeFlags.NonPrimitive */) !== 0 &&
352
+ !(relation === c.strictSubtypeRelation &&
353
+ isEmptyAnonymousObjectType(c, source) &&
354
+ (source.objectFlags & 8192 /* ObjectFlags.FreshLiteral */) === 0))
355
+ return true;
356
+ if (relation === c.assignableRelation || relation === c.comparableRelation) {
357
+ if ((s & 1 /* TypeFlags.Any */) !== 0)
358
+ return true;
359
+ // Numbers are assignable to numeric enums, for bit flags.
360
+ if ((s & 64 /* TypeFlags.Number */) !== 0 &&
361
+ ((t & 65536 /* TypeFlags.Enum */) !== 0 || ((t & 2048 /* TypeFlags.NumberLiteral */) !== 0 && (t & 32768 /* TypeFlags.EnumLiteral */) !== 0)))
362
+ return true;
363
+ if ((s & 2048 /* TypeFlags.NumberLiteral */) !== 0 &&
364
+ (s & 32768 /* TypeFlags.EnumLiteral */) === 0 &&
365
+ ((t & 65536 /* TypeFlags.Enum */) !== 0 ||
366
+ ((t & 2048 /* TypeFlags.NumberLiteral */) !== 0 && (t & 32768 /* TypeFlags.EnumLiteral */) !== 0 && sameLiteralValue(source, target))))
367
+ return true;
368
+ // Anything is assignable to a union of undefined, null and {}.
369
+ if (isUnknownLikeUnionType(c, target))
370
+ return true;
371
+ }
372
+ return false;
373
+ }
374
+ /** Whether two literal types have the same value; literals of different kinds never do. */
375
+ function sameLiteralValue(a, b) {
376
+ if (((a.flags ^ b.flags) & 15360 /* TypeFlags.Literal */) !== 0)
377
+ return false;
378
+ const x = a;
379
+ const y = b;
380
+ if ((a.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0)
381
+ return x.numberValue === y.numberValue || (x.numberValue !== x.numberValue && y.numberValue !== y.numberValue);
382
+ return x.stringValue === y.stringValue;
383
+ }
384
+ function someTypeIsEmptyAnonymousObject(c, types) {
385
+ for (const t of types)
386
+ if (isEmptyAnonymousObjectType(c, t))
387
+ return true;
388
+ return false;
389
+ }
390
+ export function isUnknownLikeUnionType(c, t) {
391
+ if (!c.strictNullChecks || (t.flags & 134217728 /* TypeFlags.Union */) === 0)
392
+ return false;
393
+ const side = sideOf(c, t);
394
+ if ((side.objectFlags & 67108864 /* ObjectFlags.IsUnknownLikeUnionComputed */) === 0) {
395
+ side.objectFlags |= 67108864 /* ObjectFlags.IsUnknownLikeUnionComputed */;
396
+ const types = typesOf(t);
397
+ if (types.length >= 3 &&
398
+ (types[0].flags & 4 /* TypeFlags.Undefined */) !== 0 &&
399
+ (types[1].flags & 8 /* TypeFlags.Null */) !== 0 &&
400
+ someTypeIsEmptyAnonymousObject(c, types))
401
+ side.objectFlags |= 134217728 /* ObjectFlags.IsUnknownLikeUnion */;
402
+ }
403
+ return (side.objectFlags & 134217728 /* ObjectFlags.IsUnknownLikeUnion */) !== 0;
404
+ }
405
+ function isEnumTypeRelatedTo(c, source, target, reporter) {
406
+ const sourceSymbol = (source.flags & 8 /* SymbolFlags.EnumMember */) !== 0 ? getParentOfSymbol(c, source) : source;
407
+ const targetSymbol = (target.flags & 8 /* SymbolFlags.EnumMember */) !== 0 ? getParentOfSymbol(c, target) : target;
408
+ if (sourceSymbol === targetSymbol)
409
+ return true;
410
+ if (sourceSymbol.name !== targetSymbol.name ||
411
+ (sourceSymbol.flags & 256 /* SymbolFlags.RegularEnum */) === 0 ||
412
+ (targetSymbol.flags & 256 /* SymbolFlags.RegularEnum */) === 0)
413
+ return false;
414
+ const key = getSymbolId(sourceSymbol) + ',' + getSymbolId(targetSymbol);
415
+ const entry = c.enumRelation.get(key) ?? 0 /* RelationComparisonResult.None */;
416
+ if (entry !== 0 /* RelationComparisonResult.None */ &&
417
+ !((entry & 2 /* RelationComparisonResult.Failed */) !== 0 && reporter !== undefined))
418
+ return (entry & 1 /* RelationComparisonResult.Succeeded */) !== 0;
419
+ const targetEnumType = getTypeOfSymbol(c, targetSymbol);
420
+ for (const sourceProperty of getPropertiesOfType(c, getTypeOfSymbol(c, sourceSymbol))) {
421
+ if ((sourceProperty.flags & 8 /* SymbolFlags.EnumMember */) === 0)
422
+ continue;
423
+ const targetProperty = getPropertyOfType(c, targetEnumType, sourceProperty.name);
424
+ if (targetProperty === undefined || (targetProperty.flags & 8 /* SymbolFlags.EnumMember */) === 0) {
425
+ if (reporter !== undefined)
426
+ reporter.reportError(502 /* Diagnostics.Property_0_is_missing_in_type_1 */, [
427
+ symbolToString(c, sourceProperty),
428
+ typeToString(c, getDeclaredTypeOfSymbol(c, targetSymbol), undefined, 1 << 6),
429
+ ]);
430
+ c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
431
+ return false;
432
+ }
433
+ const sourceDecl = sourceProperty.declarations.find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
434
+ const targetDecl = targetProperty.declarations.find((d) => d.kind === 306 /* SyntaxKind.EnumMember */);
435
+ if (sourceDecl === undefined || targetDecl === undefined)
436
+ continue;
437
+ computeEnumMemberValues(c, sourceDecl.parent);
438
+ computeEnumMemberValues(c, targetDecl.parent);
439
+ const s = c.nodeLinks(sourceDecl);
440
+ const t = c.nodeLinks(targetDecl);
441
+ const same = s.enumValueKind === t.enumValueKind &&
442
+ (s.enumValueKind === 0 ||
443
+ (s.enumValueKind === 1 ? s.enumNumberValue === t.enumNumberValue : s.enumStringValue === t.enumStringValue));
444
+ if (same)
445
+ continue;
446
+ if (s.enumValueKind !== 0 && t.enumValueKind !== 0) {
447
+ if (reporter !== undefined)
448
+ reporter.reportError(1111 /* Diagnostics.Each_declaration_of_0_1_differs_in_its_value_where_2_was_expected_but_3_was_given */, [
449
+ symbolToString(c, targetSymbol),
450
+ symbolToString(c, targetProperty),
451
+ enumValueText(t.enumValueKind, t.enumNumberValue, t.enumStringValue),
452
+ enumValueText(s.enumValueKind, s.enumNumberValue, s.enumStringValue),
453
+ ]);
454
+ c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
455
+ return false;
456
+ }
457
+ // One value is unknown, so assumed numeric; a string on the other side mismatches.
458
+ if (s.enumValueKind === 2 || t.enumValueKind === 2) {
459
+ if (reporter !== undefined) {
460
+ const known = s.enumValueKind === 2 ? s : t;
461
+ reporter.reportError(1112 /* Diagnostics.One_value_of_0_1_is_the_string_2_and_the_other_is_assumed_to_be_an_unknown_numeric_value */, [symbolToString(c, targetSymbol), symbolToString(c, targetProperty), JSON.stringify(known.enumStringValue)]);
462
+ }
463
+ c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
464
+ return false;
465
+ }
466
+ }
467
+ c.enumRelation.set(key, 1 /* RelationComparisonResult.Succeeded */);
468
+ return true;
469
+ }
470
+ function enumValueText(kind, n, s) {
471
+ return kind === 1 ? String(n) : JSON.stringify(s);
472
+ }
473
+ // ---- Keys
474
+ export class RelationKey {
475
+ key = 0;
476
+ constrained = false;
477
+ }
478
+ /** Type ids below this bound pack into a numeric relation key with the intersection state. */
479
+ const RelationKeyIdLimit = 1 << 24;
480
+ /**
481
+ * A key for the string spelling of a relation, numbered per checker. Interned keys are negative, so
482
+ * they never collide with packed keys.
483
+ */
484
+ function internRelationKey(c, text) {
485
+ let key = c.relationKeyIds.get(text);
486
+ if (key === undefined) {
487
+ key = -++c.relationKeyCount;
488
+ c.relationKeyIds.set(text, key);
489
+ }
490
+ return key;
491
+ }
492
+ /** An interned generic relation key (`writeTypeReference`'s tokens) and the next one with the same hash. */
493
+ export class InternedRelationKey {
494
+ tokens;
495
+ key;
496
+ next = undefined;
497
+ constructor(tokens, key) {
498
+ this.tokens = tokens;
499
+ this.key = key;
500
+ }
501
+ }
502
+ /** `internRelationKey` for a generic relation key spelled as tokens, without building its string. */
503
+ function internRelationKeyTokens(c, tokens) {
504
+ let h1 = 0x811c9dc5;
505
+ let h2 = 0x9e3779b9;
506
+ for (let i = 0; i < tokens.length; i++) {
507
+ const t = tokens[i];
508
+ h1 = Math.imul(h1 ^ t, 0x01000193);
509
+ h2 = Math.imul(h2 + t, 0x85ebca6b) ^ (h2 >>> 15);
510
+ }
511
+ h1 ^= h1 >>> 16;
512
+ h1 = Math.imul(h1, 0x7feb352d);
513
+ h1 ^= h1 >>> 15;
514
+ const hash = (h1 >>> 0) * 0x100000 + ((h2 ^ tokens.length) & 0xfffff);
515
+ const head = c.relationKeyTokens.get(hash);
516
+ for (let e = head; e !== undefined; e = e.next) {
517
+ const other = e.tokens;
518
+ if (other.length !== tokens.length)
519
+ continue;
520
+ let same = true;
521
+ for (let i = 0; i < tokens.length; i++)
522
+ if (other[i] !== tokens[i]) {
523
+ same = false;
524
+ break;
525
+ }
526
+ if (same)
527
+ return e.key;
528
+ }
529
+ const entry = new InternedRelationKey(tokens, -++c.relationKeyCount);
530
+ if (head === undefined)
531
+ c.relationKeyTokens.set(hash, entry);
532
+ else {
533
+ entry.next = head.next;
534
+ head.next = entry;
535
+ }
536
+ return entry.key;
537
+ }
538
+ export function getRelationKey(c, source, target, intersectionState, isIdentity, ignoreConstraints) {
539
+ if (isIdentity && source.id > target.id) {
540
+ const t = source;
541
+ source = target;
542
+ target = t;
543
+ }
544
+ const result = c.relationScratchKey;
545
+ result.constrained = false;
546
+ if (isTypeReferenceWithGenericArguments(c, source) && isTypeReferenceWithGenericArguments(c, target)) {
547
+ const typeParameters = [];
548
+ const tokens = [];
549
+ writeTypeReference(c, source, 0, typeParameters, tokens, ignoreConstraints, result);
550
+ tokens.push(11 /* RelationKeyToken.Separator */);
551
+ writeTypeReference(c, target, 0, typeParameters, tokens, ignoreConstraints, result);
552
+ tokens.push(15 /* RelationKeyToken.End */ + 4 * intersectionState);
553
+ result.key = internRelationKeyTokens(c, tokens);
554
+ }
555
+ else {
556
+ // The common case packs both ids and the intersection state (two bits) into one exact number,
557
+ // so the relation caches need no key strings.
558
+ const s = source.id;
559
+ const t = target.id;
560
+ result.key =
561
+ s < RelationKeyIdLimit && t < RelationKeyIdLimit
562
+ ? (s * RelationKeyIdLimit + t) * 4 + intersectionState
563
+ : internRelationKey(c, 's' + s + ',' + t + ':' + intersectionState);
564
+ }
565
+ return result;
566
+ }
567
+ function writeTypeReference(c, ref, depth, typeParameters, tokens, ignoreConstraints, result) {
568
+ tokens.push(ref.target.id * 4 + 0 /* RelationKeyToken.TargetId */);
569
+ for (const t of ref.resolvedTypeArguments ?? getTypeArguments(c, ref)) {
570
+ if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
571
+ if (ignoreConstraints || getConstraintFromTypeParameter(c, t) === undefined) {
572
+ let index = typeParameters.indexOf(t);
573
+ if (index < 0) {
574
+ index = typeParameters.length;
575
+ typeParameters.push(t);
576
+ }
577
+ tokens.push(index * 4 + 2 /* RelationKeyToken.TypeParameterIndex */);
578
+ continue;
579
+ }
580
+ result.constrained = true;
581
+ }
582
+ else if (depth < 4 && isTypeReferenceWithGenericArguments(c, t)) {
583
+ tokens.push(3 /* RelationKeyToken.Open */);
584
+ writeTypeReference(c, t, depth + 1, typeParameters, tokens, ignoreConstraints, result);
585
+ tokens.push(7 /* RelationKeyToken.Close */);
586
+ continue;
587
+ }
588
+ tokens.push(t.id * 4 + 1 /* RelationKeyToken.ArgumentId */);
589
+ }
590
+ }
591
+ function isTypeReferenceWithGenericArguments(c, t) {
592
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0 ||
593
+ (t.flags & 1048576 /* TypeFlags.Object */) === 0 ||
594
+ t.node !== undefined)
595
+ return false;
596
+ for (const a of getTypeArguments(c, t))
597
+ if ((a.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 || isTypeReferenceWithGenericArguments(c, a))
598
+ return true;
599
+ return false;
600
+ }
601
+ // ---- checkTypeRelatedTo
602
+ export function checkTypeAssignableTo(c, source, target, errorNode, headMessage) {
603
+ return checkTypeRelatedTo(c, source, target, c.assignableRelation, errorNode, headMessage, undefined);
604
+ }
605
+ export function checkTypeComparableTo(c, source, target, errorNode, headMessage) {
606
+ return checkTypeRelatedTo(c, source, target, c.comparableRelation, errorNode, headMessage, undefined);
607
+ }
608
+ /**
609
+ * Whether `source` is related to `target`. With an `errorNode`, reports at most one error, to
610
+ * `diagnosticOutput` when given.
611
+ */
612
+ export function checkTypeRelatedTo(c, source, target, relation, errorNode, headMessage, diagnosticOutput) {
613
+ // Nested checks (from resolving types during the relation) find no spare and allocate their own.
614
+ const r = c.spareRelater ?? new Relater(c, relation, errorNode);
615
+ c.spareRelater = undefined;
616
+ r.reset(relation, errorNode);
617
+ r.relationCount = Math.trunc((16000000 - relation.size()) / 8);
618
+ const result = r.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, errorNode !== undefined, headMessage, 0 /* IntersectionState.None */);
619
+ if (r.overflow) {
620
+ // Remember the overflow so it isn't attempted again.
621
+ const key = getRelationKey(c, source, target, 0 /* IntersectionState.None */, relation === c.identityRelation, false).key;
622
+ relation.set(key, 2 /* RelationComparisonResult.Failed */ |
623
+ (r.relationCount <= 0
624
+ ? 32 /* RelationComparisonResult.ComplexityOverflow */
625
+ : 64 /* RelationComparisonResult.StackDepthOverflow */));
626
+ const message = r.relationCount <= 0
627
+ ? 979 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */
628
+ : 499 /* Diagnostics.Excessive_stack_depth_comparing_types_0_and_1 */;
629
+ reportDiagnostic(c, createDiagnosticForNode(errorNode ?? c.currentNode, message, [typeToString(c, source), typeToString(c, target)]), diagnosticOutput);
630
+ }
631
+ else if (r.errorChain !== undefined) {
632
+ const diagnostic = createDiagnosticFromErrorChain(r.errorChain, r.errorNode, r.relatedInfo);
633
+ if (diagnostic !== undefined)
634
+ reportDiagnostic(c, diagnostic, diagnosticOutput);
635
+ }
636
+ c.spareRelater = r;
637
+ return result !== 0 /* Ternary.False */;
638
+ }
639
+ function reportDiagnostic(c, diagnostic, output) {
640
+ if (output !== undefined)
641
+ output.push(diagnostic);
642
+ else
643
+ c.addDiagnostic(diagnostic);
644
+ }
645
+ /**
646
+ * The diagnostic for an error chain, skipping elided messages; nested messages become its chain. As in tsgo, every
647
+ * message of the chain has the location and related information of the error, which build info records.
648
+ */
649
+ function createDiagnosticFromErrorChain(chain, errorNode, relatedInfo) {
650
+ while (chain !== undefined && messageElidedInCompatibilityPyramid(chain.message))
651
+ chain = chain.next;
652
+ if (chain === undefined)
653
+ return undefined;
654
+ const diagnostic = createDiagnosticForNode(errorNode, chain.message, chain.args);
655
+ for (const info of relatedInfo)
656
+ diagnostic.addRelatedInfo(info);
657
+ let next = chain.next;
658
+ let parent = diagnostic;
659
+ while (next !== undefined) {
660
+ if (!messageElidedInCompatibilityPyramid(next.message)) {
661
+ const child = new Diagnostic(diagnostic.file, diagnostic.pos, diagnostic.end, next.message, next.args);
662
+ for (const info of relatedInfo)
663
+ child.addRelatedInfo(info);
664
+ parent.addMessageChain(child);
665
+ parent = child;
666
+ }
667
+ next = next.next;
668
+ }
669
+ return diagnostic;
670
+ }
671
+ class ErrorChain {
672
+ next;
673
+ message;
674
+ args;
675
+ constructor(next, message, args) {
676
+ this.next = next;
677
+ this.message = message;
678
+ this.args = args;
679
+ }
680
+ }
681
+ function chainDepth(chain) {
682
+ let depth = 0;
683
+ for (let e = chain; e !== undefined; e = e.next)
684
+ depth++;
685
+ return depth;
686
+ }
687
+ function getPropertyNameArg(arg) {
688
+ if (arg.length !== 0) {
689
+ const ch = arg.charCodeAt(0);
690
+ if (ch === 0x22 || ch === 0x27 || ch === 0x60)
691
+ return '[' + arg + ']';
692
+ }
693
+ return arg;
694
+ }
695
+ function addToDottedName(head, tail) {
696
+ if (head.startsWith('new '))
697
+ head = '(' + head + ')';
698
+ let pos = 0;
699
+ for (;;) {
700
+ if (tail.startsWith('(', pos))
701
+ pos++;
702
+ else if (tail.startsWith('new ', pos))
703
+ pos += 4;
704
+ else
705
+ break;
706
+ }
707
+ const prefix = tail.substring(0, pos);
708
+ const suffix = tail.substring(pos);
709
+ return suffix.startsWith('[') ? prefix + head + suffix : prefix + head + '.' + suffix;
710
+ }
711
+ function isConversionOrInterfaceImplementationMessage(message) {
712
+ return (message === 591 /* Diagnostics.Class_0_incorrectly_implements_interface_1 */ ||
713
+ message ===
714
+ 852 /* Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass */ ||
715
+ message ===
716
+ 528 /* 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 */ ||
717
+ message === 920 /* Diagnostics.Its_instance_type_0_is_not_a_valid_JSX_element */ ||
718
+ message === 919 /* Diagnostics.Its_return_type_0_is_not_a_valid_JSX_element */ ||
719
+ message === 921 /* Diagnostics.Its_element_type_0_is_not_a_valid_JSX_element */);
720
+ }
721
+ // ---- The relater
722
+ /** The state of a relation check: its error chain, maybe-stack and recursion stacks. */
723
+ export class Relater extends TypeComparer {
724
+ c;
725
+ relation;
726
+ errorNode;
727
+ errorChain = undefined;
728
+ relatedInfo = [];
729
+ maybeKeys = [];
730
+ maybeKeysSet = new Set();
731
+ /** Recursion stacks: the first `sourceDepth` and `targetDepth` entries are live. */
732
+ sourceStack = [];
733
+ targetStack = [];
734
+ sourceDepth = 0;
735
+ targetDepth = 0;
736
+ expandingFlags = 0 /* ExpandingFlags.None */;
737
+ overflow = false;
738
+ relationCount = 0;
739
+ /** The intersection state passed to `compare` during signature comparisons. */
740
+ signatureIntersectionState = 0 /* IntersectionState.None */;
741
+ // What `relateVariances` changes in its caller's state when it falls back to structure.
742
+ varianceSetsCheckFailed = false;
743
+ varianceCheckFailed = false;
744
+ varianceSetsErrorChain = false;
745
+ varianceErrorChain = undefined;
746
+ constructor(c, relation, errorNode) {
747
+ super();
748
+ this.c = c;
749
+ this.relation = relation;
750
+ this.errorNode = errorNode;
751
+ }
752
+ /** Prepares this relater for a new check, as if newly constructed. */
753
+ reset(relation, errorNode) {
754
+ this.relation = relation;
755
+ this.errorNode = errorNode;
756
+ this.errorChain = undefined;
757
+ if (this.relatedInfo.length !== 0)
758
+ this.relatedInfo = [];
759
+ this.maybeKeys.length = 0;
760
+ this.maybeKeysSet.clear();
761
+ this.sourceDepth = 0;
762
+ this.targetDepth = 0;
763
+ this.expandingFlags = 0 /* ExpandingFlags.None */;
764
+ this.overflow = false;
765
+ this.relationCount = 0;
766
+ this.signatureIntersectionState = 0 /* IntersectionState.None */;
767
+ }
768
+ compare(source, target, reportErrors) {
769
+ return this.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, reportErrors, undefined, this.signatureIntersectionState);
770
+ }
771
+ report(message, args) {
772
+ this.reportError(message, args);
773
+ }
774
+ isRelatedToSimple(source, target) {
775
+ return this.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, false, undefined, 0 /* IntersectionState.None */);
776
+ }
777
+ isRelatedTo(source, target, recursionFlags, reportErrors) {
778
+ return this.isRelatedToEx(source, target, recursionFlags, reportErrors, undefined, 0 /* IntersectionState.None */);
779
+ }
780
+ isRelatedToEx(originalSource, originalTarget, recursionFlags, reportErrors, headMessage, intersectionState) {
781
+ const c = this.c;
782
+ if (originalSource === originalTarget)
783
+ return -1 /* Ternary.True */;
784
+ // An object source and primitive target only need the simple check.
785
+ if ((originalSource.flags & 1048576 /* TypeFlags.Object */) !== 0 && (originalTarget.flags & 12713980 /* TypeFlags.Primitive */) !== 0) {
786
+ if ((this.relation === c.comparableRelation &&
787
+ (originalTarget.flags & 262144 /* TypeFlags.Never */) === 0 &&
788
+ isSimpleTypeRelatedTo(c, originalTarget, originalSource, this.relation, undefined)) ||
789
+ isSimpleTypeRelatedTo(c, originalSource, originalTarget, this.relation, reportErrors ? this : undefined))
790
+ return -1 /* Ternary.True */;
791
+ if (reportErrors)
792
+ this.reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
793
+ return 0 /* Ternary.False */;
794
+ }
795
+ // Normalize: regular literals, non-deferred references, simplified types, resolved substitutions.
796
+ const source = getNormalizedType(c, originalSource, false);
797
+ let target = getNormalizedType(c, originalTarget, true);
798
+ if (source === target)
799
+ return -1 /* Ternary.True */;
800
+ if (this.relation === c.identityRelation) {
801
+ if (source.flags !== target.flags)
802
+ return 0 /* Ternary.False */;
803
+ if ((source.flags & 394239 /* TypeFlags.Singleton */) !== 0)
804
+ return -1 /* Ternary.True */;
805
+ return this.recursiveTypeRelatedTo(source, target, false, 0 /* IntersectionState.None */, recursionFlags);
806
+ }
807
+ // Fast path: a type parameter related to exactly its constraint.
808
+ if ((source.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && getConstraintOfType(c, source) === target)
809
+ return -1 /* Ternary.True */;
810
+ // A definitely non-nullable source against `T | null | undefined` only needs T.
811
+ if ((source.flags & 13893600 /* TypeFlags.DefinitelyNonNullable */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
812
+ const types = typesOf(target);
813
+ let candidate;
814
+ if (types.length === 2 && (types[0].flags & 12 /* TypeFlags.Nullable */) !== 0)
815
+ candidate = types[1];
816
+ else if (types.length === 3 &&
817
+ (types[0].flags & 12 /* TypeFlags.Nullable */) !== 0 &&
818
+ (types[1].flags & 12 /* TypeFlags.Nullable */) !== 0)
819
+ candidate = types[2];
820
+ if (candidate !== undefined && (candidate.flags & 12 /* TypeFlags.Nullable */) === 0) {
821
+ target = getNormalizedType(c, candidate, true);
822
+ if (source === target)
823
+ return -1 /* Ternary.True */;
824
+ }
825
+ }
826
+ if ((this.relation === c.comparableRelation &&
827
+ (target.flags & 262144 /* TypeFlags.Never */) === 0 &&
828
+ isSimpleTypeRelatedTo(c, target, source, this.relation, undefined)) ||
829
+ isSimpleTypeRelatedTo(c, source, target, this.relation, reportErrors ? this : undefined))
830
+ return -1 /* Ternary.True */;
831
+ if ((source.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) !== 0 ||
832
+ (target.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) !== 0) {
833
+ const isPerformingExcessPropertyChecks = (intersectionState & 2 /* IntersectionState.Target */) === 0 &&
834
+ isObjectLiteralType(source) &&
835
+ (source.objectFlags & 8192 /* ObjectFlags.FreshLiteral */) !== 0;
836
+ if (isPerformingExcessPropertyChecks && this.hasExcessProperties(source, target, reportErrors)) {
837
+ if (reportErrors)
838
+ this.reportRelationError(headMessage, source, originalTarget.alias !== undefined ? originalTarget : target);
839
+ return 0 /* Ternary.False */;
840
+ }
841
+ const isPerformingCommonPropertyChecks = (this.relation !== c.comparableRelation || isUnitType(source)) &&
842
+ (intersectionState & 2 /* IntersectionState.Target */) === 0 &&
843
+ (source.flags & (12713980 /* TypeFlags.Primitive */ | 1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0 &&
844
+ source !== c.globalObjectType &&
845
+ (target.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0 &&
846
+ isWeakType(c, target) &&
847
+ (getPropertiesOfType(c, source).length > 0 || typeHasCallOrConstructSignatures(c, source));
848
+ const isComparingJsxAttributes = (source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0;
849
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(c, source, target, isComparingJsxAttributes)) {
850
+ if (reportErrors) {
851
+ const sourceString = typeToString(c, originalSource.alias !== undefined ? originalSource : source);
852
+ const targetString = typeToString(c, originalTarget.alias !== undefined ? originalTarget : target);
853
+ const calls = getSignaturesOfType(c, source, 0 /* SignatureKind.Call */);
854
+ const constructs = getSignaturesOfType(c, source, 1 /* SignatureKind.Construct */);
855
+ if ((calls.length > 0 &&
856
+ this.isRelatedTo(getReturnTypeOfSignature(c, calls[0]), target, 1 /* RecursionFlags.Source */, false) !==
857
+ 0 /* Ternary.False */) ||
858
+ (constructs.length > 0 &&
859
+ this.isRelatedTo(getReturnTypeOfSignature(c, constructs[0]), target, 1 /* RecursionFlags.Source */, false) !==
860
+ 0 /* Ternary.False */))
861
+ this.reportError(714 /* Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it */, [sourceString, targetString]);
862
+ else
863
+ this.reportError(713 /* Diagnostics.Type_0_has_no_properties_in_common_with_type_1 */, [sourceString, targetString]);
864
+ }
865
+ return 0 /* Ternary.False */;
866
+ }
867
+ const skipCaching = ((source.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
868
+ typesOf(source).length < 4 &&
869
+ (target.flags & 134217728 /* TypeFlags.Union */) === 0) ||
870
+ ((target.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
871
+ typesOf(target).length < 4 &&
872
+ (source.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) === 0);
873
+ const result = skipCaching
874
+ ? this.unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)
875
+ : this.recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
876
+ if (result !== 0 /* Ternary.False */)
877
+ return result;
878
+ }
879
+ if (reportErrors)
880
+ this.reportErrorResults(originalSource, originalTarget, source, target, headMessage);
881
+ return 0 /* Ternary.False */;
882
+ }
883
+ hasExcessProperties(source, target, reportErrors) {
884
+ const c = this.c;
885
+ if (!isExcessPropertyCheckTarget(target) ||
886
+ (!c.noImplicitAny && (target.objectFlags & 4096 /* ObjectFlags.JSLiteral */) !== 0))
887
+ return false;
888
+ const isComparingJsxAttributes = (source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0;
889
+ if ((this.relation === c.assignableRelation || this.relation === c.comparableRelation) &&
890
+ (isTypeSubsetOf(c, c.globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(c, target))))
891
+ return false;
892
+ let reducedTarget = target;
893
+ let checkTypes;
894
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
895
+ reducedTarget =
896
+ findMatchingDiscriminantType(c, source, target, this) ?? filterPrimitivesIfContainsNonPrimitive(c, target);
897
+ checkTypes =
898
+ (reducedTarget.flags & 134217728 /* TypeFlags.Union */) !== 0
899
+ ? typesOf(reducedTarget)
900
+ : (reducedTarget.flags & 262144 /* TypeFlags.Never */) !== 0
901
+ ? emptyTypes
902
+ : [reducedTarget];
903
+ }
904
+ for (const prop of getPropertiesOfType(c, source)) {
905
+ if (!shouldCheckAsExcessProperty(prop, source.symbol) || isIgnoredJsxProperty(source, prop))
906
+ continue;
907
+ if (!isKnownProperty(c, reducedTarget, prop.name, isComparingJsxAttributes)) {
908
+ if (reportErrors) {
909
+ // Report in terms of the object types we check in isKnownProperty, at the property.
910
+ const errorTarget = filterType(c, reducedTarget, isExcessPropertyCheckTarget);
911
+ const errorNode = this.errorNode;
912
+ if (errorNode.kind === 293 /* SyntaxKind.JsxAttributes */ ||
913
+ isJsxOpeningLikeElement(errorNode) ||
914
+ (errorNode.parent !== undefined && isJsxOpeningLikeElement(errorNode.parent))) {
915
+ // Attributes are checked like object literals but reported as attributes, at the attribute.
916
+ const valueDeclaration = prop.valueDeclaration;
917
+ if (valueDeclaration !== undefined &&
918
+ valueDeclaration.kind === 292 /* SyntaxKind.JsxAttribute */ &&
919
+ sameFile(valueDeclaration, errorNode))
920
+ this.errorNode = getName(valueDeclaration);
921
+ const propName = symbolToString(c, prop);
922
+ const suggestion = getSuggestedSymbolForNonexistentJSXAttribute(c, propName, errorTarget);
923
+ if (suggestion !== undefined)
924
+ this.reportError(706 /* Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2 */, [
925
+ propName,
926
+ typeToString(c, errorTarget),
927
+ symbolToString(c, suggestion),
928
+ ]);
929
+ else
930
+ this.reportError(516 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
931
+ propName,
932
+ typeToString(c, errorTarget),
933
+ ]);
934
+ return true;
935
+ }
936
+ const objectLiteralDeclaration = source.symbol !== undefined && source.symbol.declarations.length !== 0
937
+ ? source.symbol.declarations[0]
938
+ : undefined;
939
+ const valueDeclaration = prop.valueDeclaration;
940
+ let suggestion = undefined;
941
+ if (valueDeclaration !== undefined &&
942
+ isObjectLiteralElement(valueDeclaration) &&
943
+ objectLiteralDeclaration !== undefined &&
944
+ isAncestor(valueDeclaration, objectLiteralDeclaration) &&
945
+ sameFile(objectLiteralDeclaration, this.errorNode)) {
946
+ const name = getName(valueDeclaration);
947
+ this.errorNode = name;
948
+ if (name.kind === 79 /* SyntaxKind.Identifier */)
949
+ suggestion = getSpellingSuggestionForName(c, getText(name), getPropertiesOfType(c, errorTarget), 111551 /* SymbolFlags.Value */);
950
+ }
951
+ if (suggestion !== undefined)
952
+ this.reportError(715 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */, [symbolToString(c, prop), typeToString(c, errorTarget), suggestion.name]);
953
+ else
954
+ this.reportError(529 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */, [symbolToString(c, prop), typeToString(c, errorTarget)]);
955
+ }
956
+ return true;
957
+ }
958
+ if (checkTypes !== undefined &&
959
+ this.isRelatedTo(getTypeOfSymbol(c, prop), getTypeOfPropertyInTypes(c, checkTypes, prop.name), 3 /* RecursionFlags.Both */, reportErrors) === 0 /* Ternary.False */) {
960
+ if (reportErrors)
961
+ this.reportError(504 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, prop)]);
962
+ return true;
963
+ }
964
+ }
965
+ return false;
966
+ }
967
+ unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
968
+ const c = this.c;
969
+ // Unions are deconstructed before intersections, and "each" before "some".
970
+ if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0) {
971
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
972
+ // A union from an intersection containing the target is related to it.
973
+ const sourceOrigin = source.origin;
974
+ if (sourceOrigin !== undefined &&
975
+ (sourceOrigin.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
976
+ target.alias !== undefined &&
977
+ typesOf(sourceOrigin).includes(target))
978
+ return -1 /* Ternary.True */;
979
+ const targetOrigin = target.origin;
980
+ if (targetOrigin !== undefined &&
981
+ (targetOrigin.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
982
+ source.alias !== undefined &&
983
+ typesOf(targetOrigin).includes(source))
984
+ return -1 /* Ternary.True */;
985
+ }
986
+ if (this.relation === c.comparableRelation)
987
+ return this.someTypeRelatedToType(source, target, reportErrors && (source.flags & 12713980 /* TypeFlags.Primitive */) === 0, intersectionState);
988
+ return this.eachTypeRelatedToType(source, target, reportErrors && (source.flags & 12713980 /* TypeFlags.Primitive */) === 0, intersectionState);
989
+ }
990
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0)
991
+ return this.typeRelatedToSomeType(getRegularTypeOfObjectLiteral(c, source), target, reportErrors && (source.flags & 12713980 /* TypeFlags.Primitive */) === 0 && (target.flags & 12713980 /* TypeFlags.Primitive */) === 0, intersectionState);
992
+ if ((target.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
993
+ return this.typeRelatedToEachType(source, target, reportErrors, 2 /* IntersectionState.Target */);
994
+ // For comparability with a primitive, hoist the constraints of instantiable constituents.
995
+ if (this.relation === c.comparableRelation && (target.flags & 12713980 /* TypeFlags.Primitive */) !== 0) {
996
+ const types = typesOf(source);
997
+ let changed = false;
998
+ const constraints = [];
999
+ for (const t of types) {
1000
+ const u = (t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0 ? (getBaseConstraintOfType(c, t) ?? c.unknownType) : t;
1001
+ if (u !== t)
1002
+ changed = true;
1003
+ constraints.push(u);
1004
+ }
1005
+ if (changed) {
1006
+ const reduced = getIntersectionType(c, constraints);
1007
+ if ((reduced.flags & 262144 /* TypeFlags.Never */) !== 0)
1008
+ return 0 /* Ternary.False */;
1009
+ if ((reduced.flags & 268435456 /* TypeFlags.Intersection */) === 0) {
1010
+ const result = this.isRelatedTo(reduced, target, 1 /* RecursionFlags.Source */, false);
1011
+ if (result !== 0 /* Ternary.False */)
1012
+ return result;
1013
+ return this.isRelatedTo(target, reduced, 1 /* RecursionFlags.Source */, false);
1014
+ }
1015
+ source = reduced;
1016
+ }
1017
+ }
1018
+ // Constituents related to the target, without elaboration.
1019
+ return this.someTypeRelatedToType(source, target, false, 1 /* IntersectionState.Source */);
1020
+ }
1021
+ someTypeRelatedToType(source, target, reportErrors, intersectionState) {
1022
+ const sourceTypes = typesOf(source);
1023
+ if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0 && unionContainsType(this.c, source, target))
1024
+ return -1 /* Ternary.True */;
1025
+ for (let i = 0; i < sourceTypes.length; i++) {
1026
+ const related = this.isRelatedToEx(sourceTypes[i], target, 1 /* RecursionFlags.Source */, reportErrors && i === sourceTypes.length - 1, undefined, intersectionState);
1027
+ if (related !== 0 /* Ternary.False */)
1028
+ return related;
1029
+ }
1030
+ return 0 /* Ternary.False */;
1031
+ }
1032
+ eachTypeRelatedToType(source, target, reportErrors, intersectionState) {
1033
+ let result = -1 /* Ternary.True */;
1034
+ const sourceTypes = typesOf(source);
1035
+ // Strip undefined from the target when the source can't contain it, for the correspondence fast path.
1036
+ const strippedTarget = this.getUndefinedStrippedTargetIfNeeded(source, target);
1037
+ const strippedTypes = (strippedTarget.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOf(strippedTarget) : emptyTypes;
1038
+ for (let i = 0; i < sourceTypes.length; i++) {
1039
+ const sourceType = sourceTypes[i];
1040
+ if ((strippedTarget.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
1041
+ sourceTypes.length >= strippedTypes.length &&
1042
+ sourceTypes.length % strippedTypes.length === 0) {
1043
+ // Unions that map one another relate element-wise.
1044
+ const related = this.isRelatedToEx(sourceType, strippedTypes[i % strippedTypes.length], 3 /* RecursionFlags.Both */, false, undefined, intersectionState);
1045
+ if (related !== 0 /* Ternary.False */) {
1046
+ result &= related;
1047
+ continue;
1048
+ }
1049
+ }
1050
+ const related = this.isRelatedToEx(sourceType, target, 1 /* RecursionFlags.Source */, reportErrors, undefined, intersectionState);
1051
+ if (related === 0 /* Ternary.False */)
1052
+ return 0 /* Ternary.False */;
1053
+ result &= related;
1054
+ }
1055
+ return result;
1056
+ }
1057
+ getUndefinedStrippedTargetIfNeeded(source, target) {
1058
+ if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
1059
+ (target.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
1060
+ (typesOf(source)[0].flags & 4 /* TypeFlags.Undefined */) === 0 &&
1061
+ (typesOf(target)[0].flags & 4 /* TypeFlags.Undefined */) !== 0)
1062
+ return filterType(this.c, target, (t) => (t.flags & 4 /* TypeFlags.Undefined */) === 0);
1063
+ return target;
1064
+ }
1065
+ typeRelatedToSomeType(source, target, reportErrors, intersectionState) {
1066
+ const c = this.c;
1067
+ const targetTypes = typesOf(target);
1068
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
1069
+ if (unionContainsType(c, target, source))
1070
+ return -1 /* Ternary.True */;
1071
+ if (isLiteralRelatedByPrimitiveUnionForms(c, source, target, this.relation))
1072
+ return literalRelatedToPrimitiveUnion(c, source, target) ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
1073
+ const match = getMatchingUnionConstituentForType(c, target, source);
1074
+ if (match !== undefined) {
1075
+ const related = this.isRelatedToEx(source, match, 2 /* RecursionFlags.Target */, false, undefined, intersectionState);
1076
+ if (related !== 0 /* Ternary.False */)
1077
+ return related;
1078
+ }
1079
+ }
1080
+ for (const t of targetTypes) {
1081
+ const related = this.isRelatedToEx(source, t, 2 /* RecursionFlags.Target */, false, undefined, intersectionState);
1082
+ if (related !== 0 /* Ternary.False */)
1083
+ return related;
1084
+ }
1085
+ if (reportErrors) {
1086
+ // Elaborate only against a best matching constituent.
1087
+ const best = getBestMatchingType(c, source, target, this);
1088
+ if (best !== undefined)
1089
+ this.isRelatedToEx(source, best, 2 /* RecursionFlags.Target */, true, undefined, intersectionState);
1090
+ }
1091
+ return 0 /* Ternary.False */;
1092
+ }
1093
+ typeRelatedToEachType(source, target, reportErrors, intersectionState) {
1094
+ let result = -1 /* Ternary.True */;
1095
+ for (const targetType of typesOf(target)) {
1096
+ const related = this.isRelatedToEx(source, targetType, 2 /* RecursionFlags.Target */, reportErrors, undefined, intersectionState);
1097
+ if (related === 0 /* Ternary.False */)
1098
+ return 0 /* Ternary.False */;
1099
+ result &= related;
1100
+ }
1101
+ return result;
1102
+ }
1103
+ eachTypeRelatedToSomeType(source, target) {
1104
+ let result = -1 /* Ternary.True */;
1105
+ for (const sourceType of typesOf(source)) {
1106
+ const related = this.typeRelatedToSomeType(sourceType, target, false, 0 /* IntersectionState.None */);
1107
+ if (related === 0 /* Ternary.False */)
1108
+ return 0 /* Ternary.False */;
1109
+ result &= related;
1110
+ }
1111
+ return result;
1112
+ }
1113
+ /**
1114
+ * Relates possibly recursive types: uses the global cache, assumes related when already
1115
+ * comparing the pair, assumes related for deeply nested expansions, and overflows at depth 100.
1116
+ */
1117
+ recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags) {
1118
+ const c = this.c;
1119
+ if (this.overflow)
1120
+ return 0 /* Ternary.False */;
1121
+ const keyInfo = getRelationKey(c, source, target, intersectionState, this.relation === c.identityRelation, false);
1122
+ const id = keyInfo.key;
1123
+ const constrained = keyInfo.constrained;
1124
+ const entry = this.relation.get(id);
1125
+ if (entry !== 0 /* RelationComparisonResult.None */) {
1126
+ if (reportErrors &&
1127
+ (entry & 2 /* RelationComparisonResult.Failed */) !== 0 &&
1128
+ (entry & 96 /* RelationComparisonResult.Overflow */) === 0) {
1129
+ // Redo the failed comparison to elaborate.
1130
+ }
1131
+ else {
1132
+ c.reliabilityFlags |=
1133
+ entry & (8 /* RelationComparisonResult.ReportsUnmeasurable */ | 16 /* RelationComparisonResult.ReportsUnreliable */);
1134
+ if (reportErrors && (entry & 96 /* RelationComparisonResult.Overflow */) !== 0) {
1135
+ const message = (entry & 32 /* RelationComparisonResult.ComplexityOverflow */) !== 0
1136
+ ? 979 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */
1137
+ : 499 /* Diagnostics.Excessive_stack_depth_comparing_types_0_and_1 */;
1138
+ this.reportError(message, [typeToString(c, source), typeToString(c, target)]);
1139
+ }
1140
+ return (entry & 1 /* RelationComparisonResult.Succeeded */) !== 0 ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
1141
+ }
1142
+ }
1143
+ if (this.relationCount <= 0) {
1144
+ this.overflow = true;
1145
+ return 0 /* Ternary.False */;
1146
+ }
1147
+ if (this.maybeKeysSet.has(id))
1148
+ return 3 /* Ternary.Maybe */;
1149
+ // Constrained keys also check the key with all type parameters unconstrained.
1150
+ if (constrained) {
1151
+ const broadest = getRelationKey(c, source, target, intersectionState, this.relation === c.identityRelation, true).key;
1152
+ if (this.maybeKeysSet.has(broadest))
1153
+ return 3 /* Ternary.Maybe */;
1154
+ }
1155
+ const sourceDepth = this.sourceDepth;
1156
+ const targetDepth = this.targetDepth;
1157
+ if (sourceDepth === 100 || targetDepth === 100) {
1158
+ this.overflow = true;
1159
+ return 0 /* Ternary.False */;
1160
+ }
1161
+ const maybeStart = this.maybeKeys.length;
1162
+ this.maybeKeys.push(id);
1163
+ this.maybeKeysSet.add(id);
1164
+ const saveExpandingFlags = this.expandingFlags;
1165
+ if ((recursionFlags & 1 /* RecursionFlags.Source */) !== 0) {
1166
+ setStackEntry(this.sourceStack, sourceDepth, source);
1167
+ this.sourceDepth = sourceDepth + 1;
1168
+ if ((this.expandingFlags & 1 /* ExpandingFlags.Source */) === 0 &&
1169
+ isDeeplyNestedType(c, source, this.sourceStack, sourceDepth + 1, 3))
1170
+ this.expandingFlags |= 1 /* ExpandingFlags.Source */;
1171
+ }
1172
+ if ((recursionFlags & 2 /* RecursionFlags.Target */) !== 0) {
1173
+ setStackEntry(this.targetStack, targetDepth, target);
1174
+ this.targetDepth = targetDepth + 1;
1175
+ if ((this.expandingFlags & 2 /* ExpandingFlags.Target */) === 0 &&
1176
+ isDeeplyNestedType(c, target, this.targetStack, targetDepth + 1, 3))
1177
+ this.expandingFlags |= 2 /* ExpandingFlags.Target */;
1178
+ }
1179
+ const saveReliabilityFlags = c.reliabilityFlags;
1180
+ c.reliabilityFlags = 0;
1181
+ const result = this.expandingFlags === 3 /* ExpandingFlags.Both */
1182
+ ? 3 /* Ternary.Maybe */
1183
+ : this.structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
1184
+ const propagatingVarianceFlags = c.reliabilityFlags;
1185
+ c.reliabilityFlags |= saveReliabilityFlags;
1186
+ this.sourceDepth = sourceDepth;
1187
+ this.targetDepth = targetDepth;
1188
+ this.expandingFlags = saveExpandingFlags;
1189
+ if (result !== 0 /* Ternary.False */) {
1190
+ if (result === -1 /* Ternary.True */ || (sourceDepth === 0 && targetDepth === 0)) {
1191
+ // True results, and Maybe results at depth 0, succeed; Unknown is never recorded.
1192
+ this.resetMaybeStack(maybeStart, propagatingVarianceFlags, result === -1 /* Ternary.True */ || result === 3 /* Ternary.Maybe */);
1193
+ }
1194
+ }
1195
+ else {
1196
+ // False under assumptions is false without them.
1197
+ this.relation.set(id, 2 /* RelationComparisonResult.Failed */ | propagatingVarianceFlags);
1198
+ this.relationCount--;
1199
+ this.resetMaybeStack(maybeStart, propagatingVarianceFlags, false);
1200
+ }
1201
+ return result;
1202
+ }
1203
+ resetMaybeStack(maybeStart, propagatingVarianceFlags, markAllAsSucceeded) {
1204
+ for (let i = maybeStart; i < this.maybeKeys.length; i++) {
1205
+ this.maybeKeysSet.delete(this.maybeKeys[i]);
1206
+ if (markAllAsSucceeded) {
1207
+ this.relation.set(this.maybeKeys[i], 1 /* RelationComparisonResult.Succeeded */ | propagatingVarianceFlags);
1208
+ this.relationCount--;
1209
+ }
1210
+ }
1211
+ this.maybeKeys.length = maybeStart;
1212
+ }
1213
+ structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
1214
+ const c = this.c;
1215
+ const saveChain = this.errorChain;
1216
+ const saveRelated = this.relatedInfo;
1217
+ let result = this.structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveChain, saveRelated);
1218
+ if (this.relation !== c.identityRelation) {
1219
+ // The combined constraint of an intersection (or a type parameter against a union) may relate.
1220
+ if (result === 0 /* Ternary.False */ &&
1221
+ ((source.flags & 268435456 /* TypeFlags.Intersection */) !== 0 ||
1222
+ ((source.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0))) {
1223
+ const sourceTypes = (source.flags & 268435456 /* TypeFlags.Intersection */) !== 0 ? typesOf(source) : [source];
1224
+ const constraint = getEffectiveConstraintOfIntersection(c, sourceTypes, (target.flags & 134217728 /* TypeFlags.Union */) !== 0);
1225
+ if (constraint !== undefined && everyType(constraint, (u) => u !== source))
1226
+ result = this.isRelatedToEx(constraint, target, 1 /* RecursionFlags.Source */, false, undefined, intersectionState);
1227
+ }
1228
+ // Intersection targets need an extra property check for nested excess properties and weak types.
1229
+ if (result !== 0 /* Ternary.False */ &&
1230
+ (intersectionState & 2 /* IntersectionState.Target */) === 0 &&
1231
+ (target.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
1232
+ !isGenericObjectType(c, target) &&
1233
+ (source.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0) {
1234
+ result &= this.propertiesRelatedTo(source, target, reportErrors, undefined, false, 0 /* IntersectionState.None */);
1235
+ if (result !== 0 /* Ternary.False */ &&
1236
+ isObjectLiteralType(source) &&
1237
+ (source.objectFlags & 8192 /* ObjectFlags.FreshLiteral */) !== 0)
1238
+ result &= this.indexSignaturesRelatedTo(source, target, false, reportErrors, 0 /* IntersectionState.None */);
1239
+ }
1240
+ else if (result !== 0 /* Ternary.False */ &&
1241
+ isNonGenericObjectType(c, target) &&
1242
+ !isArrayOrTupleType(c, target) &&
1243
+ isSourceIntersectionNeedingExtraCheck(c, source, target))
1244
+ // Source intersections check optional target properties for mismatched types.
1245
+ result &= this.propertiesRelatedTo(source, target, reportErrors, undefined, true, intersectionState);
1246
+ }
1247
+ if (result !== 0 /* Ternary.False */) {
1248
+ this.errorChain = saveChain;
1249
+ this.relatedInfo = saveRelated;
1250
+ }
1251
+ return result;
1252
+ }
1253
+ /**
1254
+ * Relates the type arguments of `structuredTypeRelatedToWorker`'s source and target by variance:
1255
+ * a result when variance decides, else undefined to fall back to structure, with the caller's
1256
+ * `varianceCheckFailed` and original error chain to update in the fields above. (A method rather
1257
+ * than a closure over the caller's locals, which native builds would allocate on every call.)
1258
+ */
1259
+ relateVariances(sourceArgs, targetArgs, variances, reportErrors, intersectionState, saveChain, saveRelated) {
1260
+ const result = this.typeArgumentsRelatedTo(sourceArgs, targetArgs, variances, reportErrors, intersectionState);
1261
+ if (result !== 0 /* Ternary.False */)
1262
+ return result;
1263
+ if (someVarianceHasFlags(variances, 24 /* VarianceFlags.AllowsStructuralFallback */)) {
1264
+ // Unmeasurable or unreliable variance: elide variance errors and compare structurally.
1265
+ this.varianceSetsCheckFailed = false;
1266
+ this.varianceSetsErrorChain = true;
1267
+ this.varianceErrorChain = undefined;
1268
+ this.errorChain = saveChain;
1269
+ this.relatedInfo = saveRelated;
1270
+ return undefined;
1271
+ }
1272
+ const allowStructuralFallback = hasCovariantVoidArgument(targetArgs, variances);
1273
+ this.varianceSetsCheckFailed = true;
1274
+ this.varianceCheckFailed = !allowStructuralFallback;
1275
+ this.varianceSetsErrorChain = false;
1276
+ if (variances.length !== 0 && !allowStructuralFallback) {
1277
+ // With invariant parameters, compare structurally to explain why.
1278
+ if (!(reportErrors && someVarianceIsInvariant(variances)))
1279
+ return 0 /* Ternary.False */;
1280
+ this.varianceSetsErrorChain = true;
1281
+ this.varianceErrorChain = this.errorChain;
1282
+ this.errorChain = saveChain;
1283
+ this.relatedInfo = saveRelated;
1284
+ }
1285
+ return undefined;
1286
+ }
1287
+ structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveChain, saveRelated) {
1288
+ const c = this.c;
1289
+ let result = 0 /* Ternary.False */;
1290
+ let varianceCheckFailed = false;
1291
+ let originalErrorChain;
1292
+ if (this.relation === c.identityRelation) {
1293
+ // Flags are known to be identical.
1294
+ if ((source.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
1295
+ let r = this.eachTypeRelatedToSomeType(source, target);
1296
+ if (r !== 0 /* Ternary.False */)
1297
+ r &= this.eachTypeRelatedToSomeType(target, source);
1298
+ return r;
1299
+ }
1300
+ if ((source.flags & 2097152 /* TypeFlags.Index */) !== 0)
1301
+ return this.isRelatedTo(source.target, target.target, 3 /* RecursionFlags.Both */, false);
1302
+ if ((source.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
1303
+ const s = source;
1304
+ const t = target;
1305
+ result = this.isRelatedTo(s.objectType, t.objectType, 3 /* RecursionFlags.Both */, false);
1306
+ if (result !== 0 /* Ternary.False */) {
1307
+ result &= this.isRelatedTo(s.indexType, t.indexType, 3 /* RecursionFlags.Both */, false);
1308
+ if (result !== 0 /* Ternary.False */)
1309
+ return result;
1310
+ }
1311
+ }
1312
+ else if ((source.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
1313
+ const s = source;
1314
+ const t = target;
1315
+ if (s.root.isDistributive === t.root.isDistributive) {
1316
+ result = this.isRelatedTo(s.checkType, t.checkType, 3 /* RecursionFlags.Both */, false);
1317
+ if (result !== 0 /* Ternary.False */)
1318
+ result &= this.isRelatedTo(s.extendsType, t.extendsType, 3 /* RecursionFlags.Both */, false);
1319
+ if (result !== 0 /* Ternary.False */)
1320
+ result &= this.isRelatedTo(getTrueTypeFromConditionalType(c, s), getTrueTypeFromConditionalType(c, t), 3 /* RecursionFlags.Both */, false);
1321
+ if (result !== 0 /* Ternary.False */)
1322
+ result &= this.isRelatedTo(getFalseTypeFromConditionalType(c, s), getFalseTypeFromConditionalType(c, t), 3 /* RecursionFlags.Both */, false);
1323
+ if (result !== 0 /* Ternary.False */)
1324
+ return result;
1325
+ }
1326
+ }
1327
+ else if ((source.flags & 16777216 /* TypeFlags.Substitution */) !== 0) {
1328
+ const s = source;
1329
+ const t = target;
1330
+ result = this.isRelatedTo(s.baseType, t.baseType, 3 /* RecursionFlags.Both */, false);
1331
+ if (result !== 0 /* Ternary.False */) {
1332
+ result &= this.isRelatedTo(s.constraint, t.constraint, 3 /* RecursionFlags.Both */, false);
1333
+ if (result !== 0 /* Ternary.False */)
1334
+ return result;
1335
+ }
1336
+ }
1337
+ else if ((source.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
1338
+ const s = source;
1339
+ const t = target;
1340
+ if (s.texts.length === t.texts.length && s.texts.every((x, i) => x === t.texts[i])) {
1341
+ result = -1 /* Ternary.True */;
1342
+ for (let i = 0; i < s.types.length; i++) {
1343
+ result &= this.isRelatedTo(s.types[i], t.types[i], 3 /* RecursionFlags.Both */, false);
1344
+ if (result === 0 /* Ternary.False */)
1345
+ return result;
1346
+ }
1347
+ return result;
1348
+ }
1349
+ }
1350
+ else if ((source.flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
1351
+ if (source.symbol === target.symbol)
1352
+ return this.isRelatedTo(source.target, target.target, 3 /* RecursionFlags.Both */, false);
1353
+ }
1354
+ if ((source.flags & 1048576 /* TypeFlags.Object */) === 0)
1355
+ return 0 /* Ternary.False */;
1356
+ }
1357
+ else if ((source.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0 ||
1358
+ (target.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
1359
+ result = this.unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState);
1360
+ if (result !== 0 /* Ternary.False */)
1361
+ return result;
1362
+ // Remaining cases: instantiable source, object against union, intersection against object, union or instantiable.
1363
+ if (!((source.flags & 132644864 /* TypeFlags.Instantiable */) !== 0 ||
1364
+ ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0) ||
1365
+ ((source.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
1366
+ (target.flags & (1048576 /* TypeFlags.Object */ | 134217728 /* TypeFlags.Union */ | 132644864 /* TypeFlags.Instantiable */)) !== 0)))
1367
+ return 0 /* Ternary.False */;
1368
+ }
1369
+ // Alias variance probing, for object and conditional types only.
1370
+ if ((source.flags & (1048576 /* TypeFlags.Object */ | 67108864 /* TypeFlags.Conditional */)) !== 0 &&
1371
+ source.alias !== undefined &&
1372
+ source.alias.typeArguments.length !== 0 &&
1373
+ target.alias !== undefined &&
1374
+ source.alias.symbol === target.alias.symbol &&
1375
+ !(isMarkerType(c, source) || isMarkerType(c, target))) {
1376
+ const variances = getAliasVariances(c, source.alias.symbol);
1377
+ if (variances.length === 0)
1378
+ return 1 /* Ternary.Unknown */;
1379
+ const params = c.symbolLinks(source.alias.symbol).typeParameters ?? emptyTypes;
1380
+ const minParams = getMinTypeArgumentCount(c, params);
1381
+ const inJS = source.alias.symbol.valueDeclaration !== undefined &&
1382
+ (source.alias.symbol.valueDeclaration.flags & (1 << 16)) !== 0;
1383
+ const sourceTypes = fillMissingTypeArguments(c, source.alias.typeArguments, params, minParams, inJS);
1384
+ const targetTypes = fillMissingTypeArguments(c, target.alias.typeArguments, params, minParams, inJS);
1385
+ const varianceResult = this.relateVariances(sourceTypes, targetTypes, variances, reportErrors, intersectionState, saveChain, saveRelated);
1386
+ if (varianceResult !== undefined)
1387
+ return varianceResult;
1388
+ result = 0 /* Ternary.False */;
1389
+ if (this.varianceSetsCheckFailed)
1390
+ varianceCheckFailed = this.varianceCheckFailed;
1391
+ if (this.varianceSetsErrorChain)
1392
+ originalErrorChain = this.varianceErrorChain;
1393
+ }
1394
+ // [...U] relates where U does, and U to readonly [...T] or to [...T] for mutable array constraints.
1395
+ if (isSingleElementGenericTupleType(source) && !tupleTargetOf(source).readonly) {
1396
+ result = this.isRelatedTo(getTypeArguments(c, source)[0], target, 1 /* RecursionFlags.Source */, false);
1397
+ if (result !== 0 /* Ternary.False */)
1398
+ return result;
1399
+ }
1400
+ if (isSingleElementGenericTupleType(target) &&
1401
+ (tupleTargetOf(target).readonly || isMutableArrayOrTuple(c, getBaseConstraintOrType(c, source)))) {
1402
+ result = this.isRelatedTo(source, getTypeArguments(c, target)[0], 2 /* RecursionFlags.Target */, false);
1403
+ if (result !== 0 /* Ternary.False */)
1404
+ return result;
1405
+ }
1406
+ if ((target.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
1407
+ // `{ [P in Q]: X }` relates to T when keyof T relates to Q and X to T[Q].
1408
+ if ((source.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 &&
1409
+ (source.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
1410
+ getNameTypeFromMappedType(c, source) === undefined &&
1411
+ this.isRelatedTo(getIndexType(c, target), getConstraintTypeFromMappedType(c, source), 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */) {
1412
+ if ((getMappedTypeModifiers(source) & 4 /* MappedTypeModifiers.IncludeOptional */) === 0) {
1413
+ const templateType = getTemplateTypeFromMappedType(c, source);
1414
+ const indexedAccessType = getIndexedAccessType(c, target, getTypeParameterFromMappedType(c, source));
1415
+ result = this.isRelatedTo(templateType, indexedAccessType, 3 /* RecursionFlags.Both */, reportErrors);
1416
+ if (result !== 0 /* Ternary.False */)
1417
+ return result;
1418
+ }
1419
+ }
1420
+ if (this.relation === c.comparableRelation && (source.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
1421
+ // Type parameters are comparable only when one extends the other.
1422
+ const constraint = getConstraintFromTypeParameterChecked(c, source);
1423
+ if (constraint !== undefined && someType(constraint, (u) => (u.flags & 524288 /* TypeFlags.TypeParameter */) !== 0))
1424
+ return this.isRelatedTo(constraint, target, 1 /* RecursionFlags.Source */, false);
1425
+ return 0 /* Ternary.False */;
1426
+ }
1427
+ }
1428
+ else if ((target.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
1429
+ if ((source.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
1430
+ // S[K] relates to T[J] when S relates to T and K to J.
1431
+ const s = source;
1432
+ const t = target;
1433
+ result = this.isRelatedTo(s.objectType, t.objectType, 3 /* RecursionFlags.Both */, reportErrors);
1434
+ if (result !== 0 /* Ternary.False */)
1435
+ result &= this.isRelatedTo(s.indexType, t.indexType, 3 /* RecursionFlags.Both */, reportErrors);
1436
+ if (result !== 0 /* Ternary.False */)
1437
+ return result;
1438
+ if (reportErrors)
1439
+ originalErrorChain = this.errorChain;
1440
+ }
1441
+ // S relates to T[K] when it relates to the base constraint of T[K] for writing.
1442
+ if (this.relation === c.assignableRelation || this.relation === c.comparableRelation) {
1443
+ const t = target;
1444
+ const baseObjectType = getBaseConstraintOrType(c, t.objectType);
1445
+ const baseIndexType = getBaseConstraintOrType(c, t.indexType);
1446
+ if (!isGenericObjectType(c, baseObjectType) && !isGenericIndexType(c, baseIndexType)) {
1447
+ const accessFlags = (1 << 2) | (baseObjectType !== t.objectType ? 1 << 1 : 0);
1448
+ const constraint = getIndexedAccessTypeOrUndefined(c, baseObjectType, baseIndexType, accessFlags);
1449
+ if (constraint !== undefined) {
1450
+ if (reportErrors && originalErrorChain !== undefined) {
1451
+ this.errorChain = saveChain;
1452
+ this.relatedInfo = saveRelated;
1453
+ }
1454
+ result = this.isRelatedToEx(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, undefined, intersectionState);
1455
+ if (result !== 0 /* Ternary.False */)
1456
+ return result;
1457
+ // Prefer the shorter of the two chains.
1458
+ if (reportErrors &&
1459
+ originalErrorChain !== undefined &&
1460
+ this.errorChain !== undefined &&
1461
+ chainDepth(originalErrorChain) <= chainDepth(this.errorChain))
1462
+ this.errorChain = originalErrorChain;
1463
+ }
1464
+ }
1465
+ }
1466
+ if (reportErrors)
1467
+ originalErrorChain = undefined;
1468
+ }
1469
+ else if ((target.flags & 2097152 /* TypeFlags.Index */) !== 0) {
1470
+ const targetType = target.target;
1471
+ // keyof S relates to keyof T when T relates to S.
1472
+ if ((source.flags & 2097152 /* TypeFlags.Index */) !== 0) {
1473
+ result = this.isRelatedTo(targetType, source.target, 3 /* RecursionFlags.Both */, false);
1474
+ if (result !== 0 /* Ternary.False */)
1475
+ return result;
1476
+ }
1477
+ if (isTupleType(targetType)) {
1478
+ result = this.isRelatedTo(source, getKnownKeysOfTupleType(c, targetType), 2 /* RecursionFlags.Target */, reportErrors);
1479
+ if (result !== 0 /* Ternary.False */)
1480
+ return result;
1481
+ }
1482
+ else {
1483
+ const constraint = getSimplifiedTypeOrConstraint(c, targetType);
1484
+ if (constraint !== undefined) {
1485
+ // Require True so circular constraints don't produce false positives.
1486
+ if (this.isRelatedTo(source, getIndexTypeEx(c, constraint, target.indexFlags | 4 /* IndexFlags.NoReducibleCheck */), 2 /* RecursionFlags.Target */, reportErrors) === -1 /* Ternary.True */)
1487
+ return -1 /* Ternary.True */;
1488
+ }
1489
+ else if (isGenericMappedType(c, targetType)) {
1490
+ const nameType = getNameTypeFromMappedType(c, targetType);
1491
+ const constraintType = getConstraintTypeFromMappedType(c, targetType);
1492
+ // Keys missing from the constraint may still be mapped from the apparent keys of the
1493
+ // modifiers type; the still generic name type is kept too.
1494
+ const targetKeys = nameType !== undefined && isMappedTypeWithKeyofConstraintDeclaration(c, targetType)
1495
+ ? getUnionType(c, [getApparentMappedTypeKeys(c, nameType, targetType), nameType])
1496
+ : (nameType ?? constraintType);
1497
+ if (this.isRelatedTo(source, targetKeys, 2 /* RecursionFlags.Target */, reportErrors) === -1 /* Ternary.True */)
1498
+ return -1 /* Ternary.True */;
1499
+ }
1500
+ }
1501
+ }
1502
+ else if ((target.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
1503
+ // Ten nested levels of one conditional type are assumed infinitely expanding.
1504
+ if (isDeeplyNestedType(c, target, this.targetStack, this.targetDepth, 10))
1505
+ return 3 /* Ternary.Maybe */;
1506
+ const t = target;
1507
+ if (t.root.inferTypeParameters.length === 0 &&
1508
+ !isDistributionDependent(c, t) &&
1509
+ !((source.flags & 67108864 /* TypeFlags.Conditional */) !== 0 && source.root === t.root)) {
1510
+ const skipTrue = !isTypeAssignableTo(c, getPermissiveInstantiation(c, t.checkType), getPermissiveInstantiation(c, t.extendsType));
1511
+ const skipFalse = !skipTrue &&
1512
+ isTypeAssignableTo(c, getRestrictiveInstantiation(c, t.checkType), getRestrictiveInstantiation(c, t.extendsType));
1513
+ result = skipTrue
1514
+ ? -1 /* Ternary.True */
1515
+ : this.isRelatedToEx(source, getTrueTypeFromConditionalType(c, t), 2 /* RecursionFlags.Target */, false, undefined, intersectionState);
1516
+ if (result !== 0 /* Ternary.False */) {
1517
+ result &= skipFalse
1518
+ ? -1 /* Ternary.True */
1519
+ : this.isRelatedToEx(source, getFalseTypeFromConditionalType(c, t), 2 /* RecursionFlags.Target */, false, undefined, intersectionState);
1520
+ if (result !== 0 /* Ternary.False */)
1521
+ return result;
1522
+ }
1523
+ }
1524
+ }
1525
+ else if ((target.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
1526
+ if ((source.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
1527
+ if (this.relation === c.comparableRelation)
1528
+ return templateLiteralTypesDefinitelyUnrelated(source, target)
1529
+ ? 0 /* Ternary.False */
1530
+ : -1 /* Ternary.True */;
1531
+ instantiateType(c, source, c.reportUnreliableMapper);
1532
+ }
1533
+ if (isTypeMatchedByTemplateLiteralType(c, source, target, (s, t) => this.isRelatedTo(s, t, 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */))
1534
+ return -1 /* Ternary.True */;
1535
+ }
1536
+ else if ((target.flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
1537
+ if ((source.flags & 8388608 /* TypeFlags.StringMapping */) === 0 && isMemberOfStringMapping(c, source, target))
1538
+ return -1 /* Ternary.True */;
1539
+ }
1540
+ else if (isGenericMappedType(c, target) && this.relation !== c.identityRelation) {
1541
+ const r = this.relateToGenericMappedType(source, target, reportErrors);
1542
+ if (r !== 0 /* Ternary.False */)
1543
+ return r;
1544
+ originalErrorChain = this.errorChain;
1545
+ this.errorChain = saveChain;
1546
+ this.relatedInfo = saveRelated;
1547
+ }
1548
+ if ((source.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0) {
1549
+ // Indexed access against indexed access is handled above.
1550
+ if ((source.flags & 33554432 /* TypeFlags.IndexedAccess */) === 0 || (target.flags & 33554432 /* TypeFlags.IndexedAccess */) === 0) {
1551
+ const constraint = getConstraintOfType(c, source) ?? c.unknownType;
1552
+ // Try without `this` instantiation first.
1553
+ result = this.isRelatedToEx(constraint, target, 1 /* RecursionFlags.Source */, false, undefined, intersectionState);
1554
+ if (result !== 0 /* Ternary.False */)
1555
+ return result;
1556
+ const constraintWithThis = getTypeWithThisArgument(c, constraint, source, false);
1557
+ result = this.isRelatedToEx(constraintWithThis, target, 1 /* RecursionFlags.Source */, reportErrors && constraint !== c.unknownType && (target.flags & source.flags & 524288 /* TypeFlags.TypeParameter */) === 0, undefined, intersectionState);
1558
+ if (result !== 0 /* Ternary.False */)
1559
+ return result;
1560
+ if (isMappedTypeGenericIndexedAccess(c, source)) {
1561
+ const indexConstraint = getConstraintOfType(c, source.indexType);
1562
+ if (indexConstraint !== undefined) {
1563
+ result = this.isRelatedTo(getIndexedAccessType(c, source.objectType, indexConstraint), target, 1 /* RecursionFlags.Source */, reportErrors);
1564
+ if (result !== 0 /* Ternary.False */)
1565
+ return result;
1566
+ }
1567
+ }
1568
+ }
1569
+ }
1570
+ else if ((source.flags & 2097152 /* TypeFlags.Index */) !== 0) {
1571
+ const sourceIndex = source;
1572
+ const isDeferredMappedIndex = shouldDeferIndexType(c, sourceIndex.target, sourceIndex.indexFlags) &&
1573
+ (sourceIndex.target.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0;
1574
+ result = this.isRelatedTo(c.stringNumberSymbolType, target, 1 /* RecursionFlags.Source */, reportErrors && !isDeferredMappedIndex);
1575
+ if (result !== 0 /* Ternary.False */)
1576
+ return result;
1577
+ if (isDeferredMappedIndex) {
1578
+ // The source keys come from the name type alone; its generic part could be anything.
1579
+ const mappedType = sourceIndex.target;
1580
+ const nameType = getNameTypeFromMappedType(c, mappedType);
1581
+ const sourceMappedKeys = nameType !== undefined && isMappedTypeWithKeyofConstraintDeclaration(c, mappedType)
1582
+ ? getApparentMappedTypeKeys(c, nameType, mappedType)
1583
+ : (nameType ?? getConstraintTypeFromMappedType(c, mappedType));
1584
+ result = this.isRelatedTo(sourceMappedKeys, target, 1 /* RecursionFlags.Source */, reportErrors);
1585
+ if (result !== 0 /* Ternary.False */)
1586
+ return result;
1587
+ }
1588
+ }
1589
+ else if ((source.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
1590
+ if (isDeeplyNestedType(c, source, this.sourceStack, this.sourceDepth, 10))
1591
+ return 3 /* Ternary.Maybe */;
1592
+ const s = source;
1593
+ const saveErrorChain = this.errorChain;
1594
+ if ((target.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
1595
+ const t = target;
1596
+ // Related when check types relate either way, extends types are identical, and branches relate.
1597
+ // The source's `infer` type parameters are inferred from the target's extends type.
1598
+ let sourceExtends = s.extendsType;
1599
+ let mapper = undefined;
1600
+ if (s.root.inferTypeParameters.length !== 0) {
1601
+ const context = createInferenceContext(c, s.root.inferTypeParameters, undefined, 0 /* InferenceFlags.None */, this);
1602
+ inferTypes(c, context.inferences, t.extendsType, sourceExtends, 512 /* InferencePriority.NoConstraints */ | 1024 /* InferencePriority.AlwaysStrict */, false);
1603
+ sourceExtends = instantiateType(c, sourceExtends, context.mapper);
1604
+ mapper = context.mapper;
1605
+ }
1606
+ if (isTypeIdenticalTo(c, sourceExtends, t.extendsType) &&
1607
+ (this.isRelatedTo(s.checkType, t.checkType, 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */ ||
1608
+ this.isRelatedTo(t.checkType, s.checkType, 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */)) {
1609
+ result = this.isRelatedTo(instantiateType(c, getTrueTypeFromConditionalType(c, s), mapper), getTrueTypeFromConditionalType(c, t), 3 /* RecursionFlags.Both */, reportErrors);
1610
+ if (result !== 0 /* Ternary.False */)
1611
+ result &= this.isRelatedTo(getFalseTypeFromConditionalType(c, s), getFalseTypeFromConditionalType(c, t), 3 /* RecursionFlags.Both */, reportErrors);
1612
+ if (result !== 0 /* Ternary.False */)
1613
+ return result;
1614
+ }
1615
+ }
1616
+ // A conditional relates through its default constraint, the union of its branches.
1617
+ const defaultConstraint = getDefaultConstraintOfConditionalType(c, s);
1618
+ result = this.isRelatedTo(defaultConstraint, target, 1 /* RecursionFlags.Source */, reportErrors);
1619
+ if (result !== 0 /* Ternary.False */)
1620
+ return result;
1621
+ // Its distributive constraint is too inaccurate to relate conditionals to each other.
1622
+ if ((target.flags & 67108864 /* TypeFlags.Conditional */) === 0 && hasNonCircularBaseConstraint(c, s)) {
1623
+ const distributiveConstraint = getConstraintOfDistributiveConditionalType(c, s);
1624
+ if (distributiveConstraint !== undefined) {
1625
+ this.errorChain = saveErrorChain;
1626
+ result = this.isRelatedTo(distributiveConstraint, target, 1 /* RecursionFlags.Source */, reportErrors);
1627
+ if (result !== 0 /* Ternary.False */)
1628
+ return result;
1629
+ }
1630
+ }
1631
+ }
1632
+ else if ((source.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0 && (target.flags & 1048576 /* TypeFlags.Object */) === 0) {
1633
+ if ((target.flags & 4194304 /* TypeFlags.TemplateLiteral */) === 0) {
1634
+ const constraint = getBaseConstraintOfType(c, source);
1635
+ if (constraint !== undefined && constraint !== source) {
1636
+ result = this.isRelatedTo(constraint, target, 1 /* RecursionFlags.Source */, reportErrors);
1637
+ if (result !== 0 /* Ternary.False */)
1638
+ return result;
1639
+ }
1640
+ }
1641
+ }
1642
+ else if ((source.flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
1643
+ if ((target.flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
1644
+ if (source.symbol !== target.symbol)
1645
+ return 0 /* Ternary.False */;
1646
+ result = this.isRelatedTo(source.target, target.target, 3 /* RecursionFlags.Both */, reportErrors);
1647
+ if (result !== 0 /* Ternary.False */)
1648
+ return result;
1649
+ }
1650
+ else {
1651
+ const constraint = getBaseConstraintOfType(c, source);
1652
+ if (constraint !== undefined) {
1653
+ result = this.isRelatedTo(constraint, target, 1 /* RecursionFlags.Source */, reportErrors);
1654
+ if (result !== 0 /* Ternary.False */)
1655
+ return result;
1656
+ }
1657
+ }
1658
+ }
1659
+ else {
1660
+ // An empty object relates to any mapped type with `?`.
1661
+ if (this.relation !== c.subtypeRelation &&
1662
+ this.relation !== c.strictSubtypeRelation &&
1663
+ isPartialMappedType(target) &&
1664
+ isEmptyObjectType(c, source))
1665
+ return -1 /* Ternary.True */;
1666
+ if (isGenericMappedType(c, target)) {
1667
+ if (isGenericMappedType(c, source)) {
1668
+ result = this.mappedTypeRelatedTo(source, target, reportErrors);
1669
+ if (result !== 0 /* Ternary.False */)
1670
+ return result;
1671
+ }
1672
+ return 0 /* Ternary.False */;
1673
+ }
1674
+ const sourceIsPrimitive = (source.flags & 12713980 /* TypeFlags.Primitive */) !== 0;
1675
+ if (this.relation !== c.identityRelation)
1676
+ source = getApparentType(c, source);
1677
+ else if (isGenericMappedType(c, source))
1678
+ return 0 /* Ternary.False */;
1679
+ if ((source.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 &&
1680
+ (target.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 &&
1681
+ (source.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
1682
+ (target.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
1683
+ source.target === target.target &&
1684
+ !isTupleType(source) &&
1685
+ !isMarkerType(c, source) &&
1686
+ !isMarkerType(c, target)) {
1687
+ if (isEmptyArrayLiteralType(c, source))
1688
+ return -1 /* Ternary.True */;
1689
+ // References to the same generic type relate by variance.
1690
+ const variances = getVariances(c, source.target);
1691
+ if (variances.length === 0)
1692
+ return 1 /* Ternary.Unknown */;
1693
+ const varianceResult = this.relateVariances(getTypeArguments(c, source), getTypeArguments(c, target), variances, reportErrors, intersectionState, saveChain, saveRelated);
1694
+ if (varianceResult !== undefined)
1695
+ return varianceResult;
1696
+ result = 0 /* Ternary.False */;
1697
+ if (this.varianceSetsCheckFailed)
1698
+ varianceCheckFailed = this.varianceCheckFailed;
1699
+ if (this.varianceSetsErrorChain)
1700
+ originalErrorChain = this.varianceErrorChain;
1701
+ }
1702
+ else if (isArrayType(c, target) &&
1703
+ ((isReadonlyArrayType(c, target) && everyType(source, (u) => isArrayOrTupleType(c, u))) ||
1704
+ everyType(source, isMutableTupleType))) {
1705
+ if (this.relation !== c.identityRelation)
1706
+ return this.isRelatedTo(getIndexTypeOfType(c, source, c.numberType) ?? c.anyType, getIndexTypeOfType(c, target, c.numberType) ?? c.anyType, 3 /* RecursionFlags.Both */, reportErrors);
1707
+ return 0 /* Ternary.False */;
1708
+ }
1709
+ else if (isGenericTupleType(source) && isTupleType(target) && !isGenericTupleType(target)) {
1710
+ const constraint = getBaseConstraintOrType(c, source);
1711
+ if (constraint !== source)
1712
+ return this.isRelatedTo(constraint, target, 1 /* RecursionFlags.Source */, reportErrors);
1713
+ }
1714
+ else if ((this.relation === c.subtypeRelation || this.relation === c.strictSubtypeRelation) &&
1715
+ isEmptyObjectType(c, target) &&
1716
+ (target.objectFlags & 8192 /* ObjectFlags.FreshLiteral */) !== 0 &&
1717
+ !isEmptyObjectType(c, source))
1718
+ return 0 /* Ternary.False */;
1719
+ // Structural comparison, including intersection sources aggregated as objects.
1720
+ if ((source.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0 &&
1721
+ (target.flags & 1048576 /* TypeFlags.Object */) !== 0) {
1722
+ const reportStructuralErrors = reportErrors && this.errorChain === saveChain && !sourceIsPrimitive;
1723
+ result = this.propertiesRelatedTo(source, target, reportStructuralErrors, undefined, false, intersectionState);
1724
+ if (result !== 0 /* Ternary.False */) {
1725
+ result &= this.signaturesRelatedTo(source, target, 0 /* SignatureKind.Call */, reportStructuralErrors, intersectionState);
1726
+ if (result !== 0 /* Ternary.False */) {
1727
+ result &= this.signaturesRelatedTo(source, target, 1 /* SignatureKind.Construct */, reportStructuralErrors, intersectionState);
1728
+ if (result !== 0 /* Ternary.False */)
1729
+ result &= this.indexSignaturesRelatedTo(source, target, sourceIsPrimitive, reportStructuralErrors, intersectionState);
1730
+ }
1731
+ }
1732
+ if (result !== 0 /* Ternary.False */) {
1733
+ if (!varianceCheckFailed)
1734
+ return result;
1735
+ if (originalErrorChain !== undefined)
1736
+ this.errorChain = originalErrorChain;
1737
+ else if (this.errorChain === undefined)
1738
+ this.errorChain = saveChain;
1739
+ }
1740
+ }
1741
+ // An object source relates to a discriminated union target when every combination of its
1742
+ // discriminant types matches some constituent. Errors come from checking each constituent.
1743
+ if ((source.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0 &&
1744
+ (target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
1745
+ const objectOnlyTarget = filterType(c, target, (u) => (u.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */ | 16777216 /* TypeFlags.Substitution */)) !== 0);
1746
+ if ((objectOnlyTarget.flags & 134217728 /* TypeFlags.Union */) !== 0) {
1747
+ const related = this.typeRelatedToDiscriminatedType(source, objectOnlyTarget);
1748
+ if (related !== 0 /* Ternary.False */)
1749
+ return related;
1750
+ }
1751
+ }
1752
+ }
1753
+ return 0 /* Ternary.False */;
1754
+ }
1755
+ typeRelatedToDiscriminatedType(source, target) {
1756
+ const c = this.c;
1757
+ const discriminants = [];
1758
+ for (const p of getPropertiesOfType(c, source))
1759
+ if (isDiscriminantProperty(c, target, p.name))
1760
+ discriminants.push(p);
1761
+ if (discriminants.length === 0)
1762
+ return 0 /* Ternary.False */;
1763
+ // Check the number of combinations before building them.
1764
+ let combinations = 1;
1765
+ for (const prop of discriminants) {
1766
+ combinations *= countTypes(getNonMissingTypeOfSymbol(c, prop));
1767
+ if (combinations > 25 || combinations === 0)
1768
+ return 0 /* Ternary.False */;
1769
+ }
1770
+ const discriminantTypes = [];
1771
+ const excludedProperties = new Set();
1772
+ for (const prop of discriminants) {
1773
+ const t = getNonMissingTypeOfSymbol(c, prop);
1774
+ discriminantTypes.push((t.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOf(t) : [t]);
1775
+ excludedProperties.add(prop.name);
1776
+ }
1777
+ // Each combination of discriminant types must match one or more constituents of the target.
1778
+ const skipOptional = c.strictNullChecks || this.relation === c.comparableRelation;
1779
+ const matchingTypes = [];
1780
+ const combination = discriminantTypes.map((types) => types[0]);
1781
+ for (let i = 0; i < combinations; i++) {
1782
+ let n = i;
1783
+ for (let j = discriminantTypes.length - 1; j >= 0; j--) {
1784
+ const types = discriminantTypes[j];
1785
+ combination[j] = types[n % types.length];
1786
+ n = Math.floor(n / types.length);
1787
+ }
1788
+ let hasMatch = false;
1789
+ for (const t of target.types) {
1790
+ let matches = true;
1791
+ for (let k = 0; k < discriminants.length; k++) {
1792
+ const sourceProp = discriminants[k];
1793
+ const targetProp = getPropertyOfType(c, t, sourceProp.name);
1794
+ if (targetProp === undefined) {
1795
+ matches = false;
1796
+ break;
1797
+ }
1798
+ if (sourceProp === targetProp)
1799
+ continue;
1800
+ // The source property is compared in the context of a single discriminant type.
1801
+ const related = this.propertyRelatedToEx(source, target, sourceProp, targetProp, combination[k], false, 0 /* IntersectionState.None */, skipOptional);
1802
+ if (related === 0 /* Ternary.False */) {
1803
+ matches = false;
1804
+ break;
1805
+ }
1806
+ }
1807
+ if (!matches)
1808
+ continue;
1809
+ if (!matchingTypes.includes(t))
1810
+ matchingTypes.push(t);
1811
+ hasMatch = true;
1812
+ }
1813
+ if (!hasMatch)
1814
+ return 0 /* Ternary.False */;
1815
+ }
1816
+ // The remaining non-discriminant properties of each match must relate.
1817
+ let result = -1 /* Ternary.True */;
1818
+ for (const t of matchingTypes) {
1819
+ result &= this.propertiesRelatedTo(source, t, false, excludedProperties, false, 0 /* IntersectionState.None */);
1820
+ if (result !== 0 /* Ternary.False */) {
1821
+ result &= this.signaturesRelatedTo(source, t, 0 /* SignatureKind.Call */, false, 0 /* IntersectionState.None */);
1822
+ if (result !== 0 /* Ternary.False */) {
1823
+ result &= this.signaturesRelatedTo(source, t, 1 /* SignatureKind.Construct */, false, 0 /* IntersectionState.None */);
1824
+ // Tuple element types are covered by their properties.
1825
+ if (result !== 0 /* Ternary.False */ && !(isTupleType(source) && isTupleType(t)))
1826
+ result &= this.indexSignaturesRelatedTo(source, t, false, false, 0 /* IntersectionState.None */);
1827
+ }
1828
+ }
1829
+ if (result === 0 /* Ternary.False */)
1830
+ return result;
1831
+ }
1832
+ return result;
1833
+ }
1834
+ relateToGenericMappedType(source, target, reportErrors) {
1835
+ const c = this.c;
1836
+ const keysRemapped = getNameTypeFromMappedType(c, target) !== undefined;
1837
+ const templateType = getTemplateTypeFromMappedType(c, target);
1838
+ const modifiers = getMappedTypeModifiers(target);
1839
+ if ((modifiers & 8 /* MappedTypeModifiers.ExcludeOptional */) !== 0)
1840
+ return 0 /* Ternary.False */;
1841
+ // `{ [P in Q]: S[P] }` with source S.
1842
+ if (!keysRemapped &&
1843
+ (templateType.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0 &&
1844
+ templateType.objectType === source &&
1845
+ templateType.indexType === getTypeParameterFromMappedType(c, target))
1846
+ return -1 /* Ternary.True */;
1847
+ if (isGenericMappedType(c, source))
1848
+ return 0 /* Ternary.False */;
1849
+ const targetKeys = keysRemapped
1850
+ ? getNameTypeFromMappedType(c, target)
1851
+ : getConstraintTypeFromMappedType(c, target);
1852
+ const sourceKeys = getIndexTypeEx(c, source, 2 /* IndexFlags.NoIndexSignatures */);
1853
+ const includeOptional = (modifiers & 4 /* MappedTypeModifiers.IncludeOptional */) !== 0;
1854
+ const filteredByApplicability = includeOptional ? getIntersectionType(c, [targetKeys, sourceKeys]) : undefined;
1855
+ if ((includeOptional && (filteredByApplicability.flags & 262144 /* TypeFlags.Never */) === 0) ||
1856
+ (!includeOptional && this.isRelatedTo(targetKeys, sourceKeys, 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */)) {
1857
+ const typeParameter = getTypeParameterFromMappedType(c, target);
1858
+ const nonNullComponent = filterType(c, templateType, (u) => (u.flags & 12 /* TypeFlags.Nullable */) === 0);
1859
+ if (!keysRemapped &&
1860
+ (nonNullComponent.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0 &&
1861
+ nonNullComponent.indexType === typeParameter) {
1862
+ const r = this.isRelatedTo(source, nonNullComponent.objectType, 2 /* RecursionFlags.Target */, reportErrors);
1863
+ if (r !== 0 /* Ternary.False */)
1864
+ return r;
1865
+ }
1866
+ else {
1867
+ let indexingType = typeParameter;
1868
+ if (keysRemapped)
1869
+ indexingType = filteredByApplicability ?? targetKeys;
1870
+ else if (filteredByApplicability !== undefined)
1871
+ indexingType = getIntersectionType(c, [filteredByApplicability, typeParameter]);
1872
+ const r = this.isRelatedTo(getIndexedAccessType(c, source, indexingType), templateType, 3 /* RecursionFlags.Both */, reportErrors);
1873
+ if (r !== 0 /* Ternary.False */)
1874
+ return r;
1875
+ }
1876
+ }
1877
+ return 0 /* Ternary.False */;
1878
+ }
1879
+ typeArgumentsRelatedTo(sources, targets, variances, reportErrors, intersectionState) {
1880
+ const c = this.c;
1881
+ if (sources.length !== targets.length && this.relation === c.identityRelation)
1882
+ return 0 /* Ternary.False */;
1883
+ const length = Math.min(sources.length, targets.length);
1884
+ let result = -1 /* Ternary.True */;
1885
+ for (let i = 0; i < length; i++) {
1886
+ // Without variance information, default to covariance.
1887
+ const varianceFlags = i < variances.length ? variances[i] : 1 /* VarianceFlags.Covariant */;
1888
+ const variance = varianceFlags & 7 /* VarianceFlags.VarianceMask */;
1889
+ if (variance === 4 /* VarianceFlags.Independent */)
1890
+ continue;
1891
+ const s = sources[i];
1892
+ const t = targets[i];
1893
+ let related;
1894
+ if ((varianceFlags & 8 /* VarianceFlags.Unmeasurable */) !== 0)
1895
+ related =
1896
+ this.relation === c.identityRelation
1897
+ ? this.isRelatedTo(s, t, 3 /* RecursionFlags.Both */, false)
1898
+ : compareTypesIdentical(c, s, t);
1899
+ else {
1900
+ if (c.inVarianceComputation && (varianceFlags & 16 /* VarianceFlags.Unreliable */) !== 0)
1901
+ instantiateType(c, s, c.reportUnreliableMapper);
1902
+ if (variance === 1 /* VarianceFlags.Covariant */)
1903
+ related = this.isRelatedToEx(s, t, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
1904
+ else if (variance === 2 /* VarianceFlags.Contravariant */)
1905
+ related = this.isRelatedToEx(t, s, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
1906
+ else if (variance === 3 /* VarianceFlags.Bivariant */) {
1907
+ // Contravariant without errors, then covariant with errors.
1908
+ related = this.isRelatedTo(t, s, 3 /* RecursionFlags.Both */, false);
1909
+ if (related === 0 /* Ternary.False */)
1910
+ related = this.isRelatedToEx(s, t, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
1911
+ }
1912
+ else {
1913
+ // Invariant: covariant first, then contravariant.
1914
+ related = this.isRelatedToEx(s, t, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
1915
+ if (related !== 0 /* Ternary.False */)
1916
+ related &= this.isRelatedToEx(t, s, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
1917
+ }
1918
+ }
1919
+ if (related === 0 /* Ternary.False */)
1920
+ return 0 /* Ternary.False */;
1921
+ result &= related;
1922
+ }
1923
+ return result;
1924
+ }
1925
+ mappedTypeRelatedTo(source, target, reportErrors) {
1926
+ const c = this.c;
1927
+ const modifiersRelated = this.relation === c.comparableRelation ||
1928
+ (this.relation === c.identityRelation && getMappedTypeModifiers(source) === getMappedTypeModifiers(target)) ||
1929
+ (this.relation !== c.identityRelation &&
1930
+ getCombinedMappedTypeOptionality(c, source) <= getCombinedMappedTypeOptionality(c, target));
1931
+ if (!modifiersRelated)
1932
+ return 0 /* Ternary.False */;
1933
+ const targetConstraint = getConstraintTypeFromMappedType(c, target);
1934
+ const sourceConstraint = instantiateType(c, getConstraintTypeFromMappedType(c, source), getCombinedMappedTypeOptionality(c, source) < 0 ? c.reportUnmeasurableMapper : c.reportUnreliableMapper);
1935
+ const result = this.isRelatedTo(targetConstraint, sourceConstraint, 3 /* RecursionFlags.Both */, reportErrors);
1936
+ if (result === 0 /* Ternary.False */)
1937
+ return 0 /* Ternary.False */;
1938
+ const mapper = new SimpleTypeMapper(getTypeParameterFromMappedType(c, source), getTypeParameterFromMappedType(c, target));
1939
+ const sourceName = getNameTypeFromMappedType(c, source);
1940
+ const targetName = getNameTypeFromMappedType(c, target);
1941
+ if ((sourceName === undefined ? undefined : instantiateType(c, sourceName, mapper)) !==
1942
+ (targetName === undefined ? undefined : instantiateType(c, targetName, mapper)))
1943
+ return 0 /* Ternary.False */;
1944
+ return (result &
1945
+ this.isRelatedTo(instantiateType(c, getTemplateTypeFromMappedType(c, source), mapper), getTemplateTypeFromMappedType(c, target), 3 /* RecursionFlags.Both */, reportErrors));
1946
+ }
1947
+ propertiesRelatedTo(source, target, reportErrors, excludedProperties, optionalsOnly, intersectionState) {
1948
+ const c = this.c;
1949
+ if (this.relation === c.identityRelation)
1950
+ return this.propertiesIdenticalTo(source, target, excludedProperties);
1951
+ let result = -1 /* Ternary.True */;
1952
+ if (isTupleType(target)) {
1953
+ const targetTuple = tupleTargetOf(target);
1954
+ if (isArrayOrTupleType(c, source)) {
1955
+ if (!targetTuple.readonly &&
1956
+ (isReadonlyArrayType(c, source) || (isTupleType(source) && tupleTargetOf(source).readonly)))
1957
+ return 0 /* Ternary.False */;
1958
+ const sourceArity = getTypeReferenceArity(source);
1959
+ const targetArity = getTypeReferenceArity(target);
1960
+ const sourceRest = isTupleType(source) ? (tupleTargetOf(source).combinedFlags & 4 /* ElementFlags.Rest */) !== 0 : true;
1961
+ const targetHasRestElement = (targetTuple.combinedFlags & 12 /* ElementFlags.Variable */) !== 0;
1962
+ const sourceMinLength = isTupleType(source) ? tupleTargetOf(source).minLength : 0;
1963
+ const targetMinLength = targetTuple.minLength;
1964
+ if (!sourceRest && sourceArity < targetMinLength) {
1965
+ if (reportErrors)
1966
+ this.reportError(762 /* Diagnostics.Source_has_0_element_s_but_target_requires_1 */, [
1967
+ String(sourceArity),
1968
+ String(targetMinLength),
1969
+ ]);
1970
+ return 0 /* Ternary.False */;
1971
+ }
1972
+ if (!targetHasRestElement && targetArity < sourceMinLength) {
1973
+ if (reportErrors)
1974
+ this.reportError(763 /* Diagnostics.Source_has_0_element_s_but_target_allows_only_1 */, [
1975
+ String(sourceMinLength),
1976
+ String(targetArity),
1977
+ ]);
1978
+ return 0 /* Ternary.False */;
1979
+ }
1980
+ if (!targetHasRestElement && (sourceRest || targetArity < sourceArity)) {
1981
+ if (reportErrors) {
1982
+ if (sourceMinLength < targetMinLength)
1983
+ this.reportError(764 /* Diagnostics.Target_requires_0_element_s_but_source_may_have_fewer */, [
1984
+ String(targetMinLength),
1985
+ ]);
1986
+ else
1987
+ this.reportError(765 /* Diagnostics.Target_allows_only_0_element_s_but_source_may_have_more */, [
1988
+ String(targetArity),
1989
+ ]);
1990
+ }
1991
+ return 0 /* Ternary.False */;
1992
+ }
1993
+ const sourceTypeArguments = getTypeArguments(c, source);
1994
+ const targetTypeArguments = getTypeArguments(c, target);
1995
+ const targetStartCount = getStartElementCount(targetTuple, 11 /* ElementFlags.NonRest */);
1996
+ const targetEndCount = getEndElementCount(targetTuple, 11 /* ElementFlags.NonRest */);
1997
+ let canExcludeDiscriminants = excludedProperties !== undefined && excludedProperties.size !== 0;
1998
+ for (let sourcePosition = 0; sourcePosition < sourceArity; sourcePosition++) {
1999
+ const sourceFlags = isTupleType(source)
2000
+ ? tupleTargetOf(source).elementInfos[sourcePosition].flags
2001
+ : 4 /* ElementFlags.Rest */;
2002
+ const sourcePositionFromEnd = sourceArity - 1 - sourcePosition;
2003
+ const targetPosition = targetHasRestElement && sourcePosition >= targetStartCount
2004
+ ? targetArity - 1 - Math.min(sourcePositionFromEnd, targetEndCount)
2005
+ : sourcePosition;
2006
+ const targetFlags = targetPosition >= 0 ? targetTuple.elementInfos[targetPosition].flags : 0 /* ElementFlags.None */;
2007
+ if ((targetFlags & 8 /* ElementFlags.Variadic */) !== 0 && (sourceFlags & 8 /* ElementFlags.Variadic */) === 0) {
2008
+ if (reportErrors)
2009
+ this.reportError(767 /* Diagnostics.Source_provides_no_match_for_variadic_element_at_position_0_in_target */, [
2010
+ String(targetPosition),
2011
+ ]);
2012
+ return 0 /* Ternary.False */;
2013
+ }
2014
+ if ((sourceFlags & 8 /* ElementFlags.Variadic */) !== 0 && (targetFlags & 12 /* ElementFlags.Variable */) === 0) {
2015
+ if (reportErrors)
2016
+ this.reportError(768 /* Diagnostics.Variadic_element_at_position_0_in_source_does_not_match_element_at_position_1_in_target */, [String(sourcePosition), String(targetPosition)]);
2017
+ return 0 /* Ternary.False */;
2018
+ }
2019
+ if ((targetFlags & 1 /* ElementFlags.Required */) !== 0 && (sourceFlags & 1 /* ElementFlags.Required */) === 0) {
2020
+ if (reportErrors)
2021
+ this.reportError(766 /* Diagnostics.Source_provides_no_match_for_required_element_at_position_0_in_target */, [
2022
+ String(targetPosition),
2023
+ ]);
2024
+ return 0 /* Ternary.False */;
2025
+ }
2026
+ if (canExcludeDiscriminants) {
2027
+ if ((sourceFlags & 12 /* ElementFlags.Variable */) !== 0 || (targetFlags & 12 /* ElementFlags.Variable */) !== 0)
2028
+ canExcludeDiscriminants = false;
2029
+ if (canExcludeDiscriminants && excludedProperties.has(String(sourcePosition)))
2030
+ continue;
2031
+ }
2032
+ const sourceType = removeMissingType(c, sourceTypeArguments[sourcePosition], (sourceFlags & targetFlags & 2 /* ElementFlags.Optional */) !== 0);
2033
+ const targetType = targetTypeArguments[targetPosition];
2034
+ const targetCheckType = (sourceFlags & 8 /* ElementFlags.Variadic */) !== 0 && (targetFlags & 4 /* ElementFlags.Rest */) !== 0
2035
+ ? createArrayTypeEx(c, targetType, false)
2036
+ : removeMissingType(c, targetType, (targetFlags & 2 /* ElementFlags.Optional */) !== 0);
2037
+ const related = this.isRelatedToEx(sourceType, targetCheckType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
2038
+ if (related === 0 /* Ternary.False */) {
2039
+ if (reportErrors && (targetArity > 1 || sourceArity > 1)) {
2040
+ if (targetHasRestElement &&
2041
+ sourcePosition >= targetStartCount &&
2042
+ sourcePositionFromEnd >= targetEndCount &&
2043
+ targetStartCount !== sourceArity - targetEndCount - 1)
2044
+ this.reportError(770 /* Diagnostics.Type_at_positions_0_through_1_in_source_is_not_compatible_with_type_at_position_2_in_target */, [String(targetStartCount), String(sourceArity - targetEndCount - 1), String(targetPosition)]);
2045
+ else
2046
+ this.reportError(769 /* Diagnostics.Type_at_position_0_in_source_is_not_compatible_with_type_at_position_1_in_target */, [String(sourcePosition), String(targetPosition)]);
2047
+ }
2048
+ return 0 /* Ternary.False */;
2049
+ }
2050
+ result &= related;
2051
+ }
2052
+ return result;
2053
+ }
2054
+ if ((targetTuple.combinedFlags & 12 /* ElementFlags.Variable */) !== 0)
2055
+ return 0 /* Ternary.False */;
2056
+ }
2057
+ const requireOptionalProperties = (this.relation === c.subtypeRelation || this.relation === c.strictSubtypeRelation) &&
2058
+ !isObjectLiteralType(source) &&
2059
+ !isEmptyArrayLiteralType(c, source) &&
2060
+ !isTupleType(source);
2061
+ const unmatchedProperty = getUnmatchedProperty(c, source, target, requireOptionalProperties, false);
2062
+ if (unmatchedProperty !== undefined) {
2063
+ if (reportErrors && shouldReportUnmatchedPropertyError(c, source, target))
2064
+ this.reportUnmatchedProperty(source, target, unmatchedProperty, requireOptionalProperties);
2065
+ return 0 /* Ternary.False */;
2066
+ }
2067
+ if (isObjectLiteralType(target)) {
2068
+ for (const sourceProp of getPropertiesOfType(c, source)) {
2069
+ if (excludedProperties !== undefined && excludedProperties.has(sourceProp.name))
2070
+ continue;
2071
+ if (getPropertyOfObjectType(c, target, sourceProp.name) === undefined) {
2072
+ if (reportErrors)
2073
+ this.reportError(516 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
2074
+ symbolToString(c, sourceProp),
2075
+ typeToString(c, target),
2076
+ ]);
2077
+ return 0 /* Ternary.False */;
2078
+ }
2079
+ }
2080
+ }
2081
+ const numericNamesOnly = isTupleType(source) && isTupleType(target);
2082
+ for (const targetProp of getPropertiesOfType(c, target)) {
2083
+ if (excludedProperties !== undefined && excludedProperties.has(targetProp.name))
2084
+ continue;
2085
+ const name = targetProp.name;
2086
+ if ((targetProp.flags & 4194304 /* SymbolFlags.Prototype */) === 0 &&
2087
+ (!numericNamesOnly || isNumericLiteralName(name) || name === 'length') &&
2088
+ (!optionalsOnly || (targetProp.flags & 16777216 /* SymbolFlags.Optional */) !== 0)) {
2089
+ const sourceProp = getPropertyOfType(c, source, name);
2090
+ if (sourceProp !== undefined && sourceProp !== targetProp) {
2091
+ const related = this.propertyRelatedTo(source, target, sourceProp, targetProp, reportErrors, intersectionState, this.relation === c.comparableRelation);
2092
+ if (related === 0 /* Ternary.False */)
2093
+ return 0 /* Ternary.False */;
2094
+ result &= related;
2095
+ }
2096
+ }
2097
+ }
2098
+ return result;
2099
+ }
2100
+ propertyRelatedTo(source, target, sourceProp, targetProp, reportErrors, intersectionState, skipOptional) {
2101
+ return this.propertyRelatedToEx(source, target, sourceProp, targetProp, undefined, reportErrors, intersectionState, skipOptional);
2102
+ }
2103
+ /** `propertyRelatedTo` with `sourcePropType` in place of the source property's type when given. */
2104
+ propertyRelatedToEx(source, target, sourceProp, targetProp, sourcePropType, reportErrors, intersectionState, skipOptional) {
2105
+ const c = this.c;
2106
+ const sourcePropFlags = getDeclarationModifierFlagsFromSymbol(c, sourceProp, false);
2107
+ const targetPropFlags = getDeclarationModifierFlagsFromSymbol(c, targetProp, false);
2108
+ if ((sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0 || (targetPropFlags & 2 /* ModifierFlags.Private */) !== 0) {
2109
+ if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
2110
+ if (reportErrors) {
2111
+ if ((sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0 && (targetPropFlags & 2 /* ModifierFlags.Private */) !== 0)
2112
+ this.reportError(610 /* Diagnostics.Types_have_separate_declarations_of_a_private_property_0 */, [
2113
+ symbolToString(c, targetProp),
2114
+ ]);
2115
+ else {
2116
+ const sourceIsPrivate = (sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0;
2117
+ this.reportError(503 /* Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2 */, [
2118
+ symbolToString(c, targetProp),
2119
+ typeToString(c, sourceIsPrivate ? source : target),
2120
+ typeToString(c, sourceIsPrivate ? target : source),
2121
+ ]);
2122
+ }
2123
+ }
2124
+ return 0 /* Ternary.False */;
2125
+ }
2126
+ }
2127
+ else if ((targetPropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
2128
+ if (!isValidOverrideOf(c, sourceProp, targetProp)) {
2129
+ if (reportErrors)
2130
+ this.reportError(611 /* Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2 */, [
2131
+ symbolToString(c, targetProp),
2132
+ typeToString(c, getDeclaringClass(c, sourceProp) ?? source),
2133
+ typeToString(c, getDeclaringClass(c, targetProp) ?? target),
2134
+ ]);
2135
+ return 0 /* Ternary.False */;
2136
+ }
2137
+ }
2138
+ else if ((sourcePropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
2139
+ if (reportErrors)
2140
+ this.reportError(612 /* Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2 */, [
2141
+ symbolToString(c, targetProp),
2142
+ typeToString(c, source),
2143
+ typeToString(c, target),
2144
+ ]);
2145
+ return 0 /* Ternary.False */;
2146
+ }
2147
+ // Under strict subtype, readonly properties aren't subtypes of mutable ones.
2148
+ if (this.relation === c.strictSubtypeRelation &&
2149
+ isReadonlySymbol(c, sourceProp) &&
2150
+ !isReadonlySymbol(c, targetProp))
2151
+ return 0 /* Ternary.False */;
2152
+ const related = this.isPropertySymbolTypeRelated(sourceProp, targetProp, sourcePropType, reportErrors, intersectionState);
2153
+ if (related === 0 /* Ternary.False */) {
2154
+ if (reportErrors)
2155
+ this.reportError(504 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, targetProp)]);
2156
+ return 0 /* Ternary.False */;
2157
+ }
2158
+ if (!skipOptional &&
2159
+ (sourceProp.flags & 16777216 /* SymbolFlags.Optional */) !== 0 &&
2160
+ (targetProp.flags & 106500 /* SymbolFlags.ClassMember */) !== 0 &&
2161
+ (targetProp.flags & 16777216 /* SymbolFlags.Optional */) === 0) {
2162
+ if (reportErrors)
2163
+ this.reportError(505 /* Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2 */, [
2164
+ symbolToString(c, targetProp),
2165
+ typeToString(c, source),
2166
+ typeToString(c, target),
2167
+ ]);
2168
+ return 0 /* Ternary.False */;
2169
+ }
2170
+ return related;
2171
+ }
2172
+ isPropertySymbolTypeRelated(sourceProp, targetProp, sourcePropType, reportErrors, intersectionState) {
2173
+ const c = this.c;
2174
+ const targetIsOptional = c.strictNullChecks && (targetProp.checkFlags & 48 /* CheckFlags.Partial */) !== 0;
2175
+ const effectiveTarget = addOptionality(c, getNonMissingTypeOfSymbol(c, targetProp), false, targetIsOptional);
2176
+ if ((effectiveTarget.flags & (this.relation === c.strictSubtypeRelation ? 1 /* TypeFlags.Any */ : 3 /* TypeFlags.AnyOrUnknown */)) !==
2177
+ 0)
2178
+ return -1 /* Ternary.True */;
2179
+ const effectiveSource = sourcePropType ?? getNonMissingTypeOfSymbol(c, sourceProp);
2180
+ return this.isRelatedToEx(effectiveSource, effectiveTarget, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
2181
+ }
2182
+ reportUnmatchedProperty(source, target, unmatchedProperty, requireOptionalProperties) {
2183
+ const c = this.c;
2184
+ // A private name of the same description in the source class is a different member.
2185
+ const declarationName = unmatchedProperty.valueDeclaration !== undefined ? getName(unmatchedProperty.valueDeclaration) : undefined;
2186
+ if (declarationName !== undefined &&
2187
+ declarationName.kind === 80 /* SyntaxKind.PrivateIdentifier */ &&
2188
+ source.symbol !== undefined &&
2189
+ (source.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
2190
+ const description = getText(declarationName);
2191
+ if (getPropertyOfType(c, source, getSymbolNameForPrivateIdentifier(source.symbol, description)) !== undefined) {
2192
+ this.reportError(1837 /* Diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2 */, [description, symbolToString(c, source.symbol), symbolToString(c, target.symbol)]);
2193
+ return;
2194
+ }
2195
+ }
2196
+ const props = getUnmatchedProperties(c, source, target, requireOptionalProperties);
2197
+ if (props.length === 1) {
2198
+ const names = getTypeNamesForErrorDisplay(c, source, target);
2199
+ const propName = symbolToString(c, unmatchedProperty);
2200
+ this.reportError(873 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */, [
2201
+ propName,
2202
+ names[0],
2203
+ names[1],
2204
+ ]);
2205
+ if (unmatchedProperty.declarations.length !== 0)
2206
+ this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declarations[0], 860 /* Diagnostics.X_0_is_declared_here */, [propName]));
2207
+ }
2208
+ else if (this.tryElaborateArrayLikeErrors(source, target, false)) {
2209
+ const names = getTypeNamesForErrorDisplay(c, source, target);
2210
+ if (props.length > 5)
2211
+ this.reportError(872 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more */, [
2212
+ names[0],
2213
+ names[1],
2214
+ symbolNames(c, props.slice(0, 4)),
2215
+ String(props.length - 4),
2216
+ ]);
2217
+ else
2218
+ this.reportError(871 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2 */, [
2219
+ names[0],
2220
+ names[1],
2221
+ symbolNames(c, props),
2222
+ ]);
2223
+ }
2224
+ }
2225
+ /** Mutability elaborations; false when property elaborations should be skipped. */
2226
+ tryElaborateArrayLikeErrors(source, target, reportErrors) {
2227
+ const c = this.c;
2228
+ if (isTupleType(source)) {
2229
+ if (tupleTargetOf(source).readonly && isMutableArrayOrTuple(c, target)) {
2230
+ if (reportErrors)
2231
+ this.reportError(1090 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
2232
+ typeToString(c, source),
2233
+ typeToString(c, target),
2234
+ ]);
2235
+ return false;
2236
+ }
2237
+ return isArrayOrTupleType(c, target);
2238
+ }
2239
+ if (isReadonlyArrayType(c, source) && isMutableArrayOrTuple(c, target)) {
2240
+ if (reportErrors)
2241
+ this.reportError(1090 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
2242
+ typeToString(c, source),
2243
+ typeToString(c, target),
2244
+ ]);
2245
+ return false;
2246
+ }
2247
+ if (isTupleType(target))
2248
+ return isArrayType(c, source);
2249
+ return true;
2250
+ }
2251
+ propertiesIdenticalTo(source, target, excludedProperties) {
2252
+ const c = this.c;
2253
+ if ((source.flags & 1048576 /* TypeFlags.Object */) === 0 || (target.flags & 1048576 /* TypeFlags.Object */) === 0)
2254
+ return 0 /* Ternary.False */;
2255
+ const exclude = (props) => excludedProperties === undefined || excludedProperties.size === 0
2256
+ ? props
2257
+ : props.filter((p) => !excludedProperties.has(p.name));
2258
+ const sourceProperties = exclude(getPropertiesOfObjectType(c, source));
2259
+ const targetProperties = exclude(getPropertiesOfObjectType(c, target));
2260
+ if (sourceProperties.length !== targetProperties.length)
2261
+ return 0 /* Ternary.False */;
2262
+ let result = -1 /* Ternary.True */;
2263
+ for (const sourceProp of sourceProperties) {
2264
+ const targetProp = getPropertyOfObjectType(c, target, sourceProp.name);
2265
+ if (targetProp === undefined)
2266
+ return 0 /* Ternary.False */;
2267
+ const related = comparePropertiesWith(c, sourceProp, targetProp, this);
2268
+ if (related === 0 /* Ternary.False */)
2269
+ return 0 /* Ternary.False */;
2270
+ result &= related;
2271
+ }
2272
+ return result;
2273
+ }
2274
+ signaturesRelatedTo(source, target, kind, reportErrors, intersectionState) {
2275
+ const c = this.c;
2276
+ if (this.relation === c.identityRelation)
2277
+ return this.signaturesIdenticalTo(source, target, kind);
2278
+ // anyFunctionType is a subtype of every function type.
2279
+ if (source === c.anyFunctionType)
2280
+ return -1 /* Ternary.True */;
2281
+ if (target === c.anyFunctionType)
2282
+ return 0 /* Ternary.False */;
2283
+ const sourceSignatures = getSignaturesOfType(c, source, kind);
2284
+ const targetSignatures = getSignaturesOfType(c, target, kind);
2285
+ if (kind === 1 /* SignatureKind.Construct */ && sourceSignatures.length !== 0 && targetSignatures.length !== 0) {
2286
+ const sourceIsAbstract = (sourceSignatures[0].flags & 8 /* SignatureFlags.Abstract */) !== 0;
2287
+ const targetIsAbstract = (targetSignatures[0].flags & 8 /* SignatureFlags.Abstract */) !== 0;
2288
+ if (sourceIsAbstract && !targetIsAbstract) {
2289
+ if (reportErrors)
2290
+ this.reportError(677 /* Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type */, []);
2291
+ return 0 /* Ternary.False */;
2292
+ }
2293
+ if (!this.constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors))
2294
+ return 0 /* Ternary.False */;
2295
+ }
2296
+ let result = -1 /* Ternary.True */;
2297
+ if (((source.objectFlags & 64 /* ObjectFlags.Instantiated */) !== 0 &&
2298
+ (target.objectFlags & 64 /* ObjectFlags.Instantiated */) !== 0 &&
2299
+ source.symbol === target.symbol) ||
2300
+ ((source.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 &&
2301
+ (target.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 &&
2302
+ source.target === target.target)) {
2303
+ // Instantiations of the same type compare pairwise with erased type parameters.
2304
+ for (let i = 0; i < targetSignatures.length && i < sourceSignatures.length; i++) {
2305
+ const related = this.signatureRelatedTo(sourceSignatures[i], targetSignatures[i], true, reportErrors, intersectionState);
2306
+ if (related === 0 /* Ternary.False */)
2307
+ return 0 /* Ternary.False */;
2308
+ result &= related;
2309
+ }
2310
+ }
2311
+ else if (sourceSignatures.length === 1 && targetSignatures.length === 1) {
2312
+ // Single signatures erase generics only for comparability.
2313
+ const eraseGenerics = this.relation === c.comparableRelation;
2314
+ result = this.signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors, intersectionState);
2315
+ }
2316
+ else {
2317
+ outer: for (const t of targetSignatures) {
2318
+ const saveChain = this.errorChain;
2319
+ const saveRelated = this.relatedInfo;
2320
+ // Elaborate only the first failure.
2321
+ let shouldElaborateErrors = reportErrors;
2322
+ for (const s of sourceSignatures) {
2323
+ const related = this.signatureRelatedTo(s, t, true, shouldElaborateErrors, intersectionState);
2324
+ if (related !== 0 /* Ternary.False */) {
2325
+ result &= related;
2326
+ this.errorChain = saveChain;
2327
+ this.relatedInfo = saveRelated;
2328
+ continue outer;
2329
+ }
2330
+ shouldElaborateErrors = false;
2331
+ }
2332
+ if (shouldElaborateErrors)
2333
+ this.reportError(792 /* Diagnostics.Type_0_provides_no_match_for_the_signature_1 */, [
2334
+ typeToString(c, source),
2335
+ signatureToString(c, t),
2336
+ ]);
2337
+ return 0 /* Ternary.False */;
2338
+ }
2339
+ }
2340
+ return result;
2341
+ }
2342
+ constructorVisibilitiesAreCompatible(sourceSignature, targetSignature, reportErrors) {
2343
+ if (sourceSignature.declaration === undefined || targetSignature.declaration === undefined)
2344
+ return true;
2345
+ const sourceAccessibility = getCombinedModifierFlags(sourceSignature.declaration) & 6 /* ModifierFlags.NonPublicAccessibilityModifier */;
2346
+ const targetAccessibility = getCombinedModifierFlags(targetSignature.declaration) & 6 /* ModifierFlags.NonPublicAccessibilityModifier */;
2347
+ if (targetAccessibility === 2 /* ModifierFlags.Private */)
2348
+ return true;
2349
+ if (targetAccessibility === 4 /* ModifierFlags.Protected */ && sourceAccessibility !== 2 /* ModifierFlags.Private */)
2350
+ return true;
2351
+ if (targetAccessibility !== 4 /* ModifierFlags.Protected */ && sourceAccessibility === 0)
2352
+ return true;
2353
+ if (reportErrors)
2354
+ this.reportError(806 /* Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type */, [
2355
+ visibilityToString(sourceAccessibility),
2356
+ visibilityToString(targetAccessibility),
2357
+ ]);
2358
+ return false;
2359
+ }
2360
+ signatureRelatedTo(source, target, erase, reportErrors, intersectionState) {
2361
+ const c = this.c;
2362
+ let checkMode = 0 /* SignatureCheckMode.None */;
2363
+ if (this.relation === c.subtypeRelation)
2364
+ checkMode = 16 /* SignatureCheckMode.StrictTopSignature */;
2365
+ else if (this.relation === c.strictSubtypeRelation)
2366
+ checkMode = 16 /* SignatureCheckMode.StrictTopSignature */ | 8 /* SignatureCheckMode.StrictArity */;
2367
+ if (erase) {
2368
+ source = getErasedSignature(c, source);
2369
+ target = getErasedSignature(c, target);
2370
+ }
2371
+ const saveState = this.signatureIntersectionState;
2372
+ this.signatureIntersectionState = intersectionState;
2373
+ const result = compareSignaturesRelated(c, source, target, checkMode, reportErrors, this, c.reportUnreliableMapper);
2374
+ this.signatureIntersectionState = saveState;
2375
+ return result;
2376
+ }
2377
+ signaturesIdenticalTo(source, target, kind) {
2378
+ const c = this.c;
2379
+ const sourceSignatures = getSignaturesOfType(c, source, kind);
2380
+ const targetSignatures = getSignaturesOfType(c, target, kind);
2381
+ if (sourceSignatures.length !== targetSignatures.length)
2382
+ return 0 /* Ternary.False */;
2383
+ let result = -1 /* Ternary.True */;
2384
+ for (let i = 0; i < sourceSignatures.length; i++) {
2385
+ const related = compareSignaturesIdenticalWith(c, sourceSignatures[i], targetSignatures[i], false, false, false, this);
2386
+ if (related === 0 /* Ternary.False */)
2387
+ return 0 /* Ternary.False */;
2388
+ result &= related;
2389
+ }
2390
+ return result;
2391
+ }
2392
+ indexSignaturesRelatedTo(source, target, sourceIsPrimitive, reportErrors, intersectionState) {
2393
+ const c = this.c;
2394
+ if (this.relation === c.identityRelation)
2395
+ return this.indexSignaturesIdenticalTo(source, target);
2396
+ const indexInfos = getIndexInfosOfType(c, target);
2397
+ const targetHasStringIndex = indexInfos.some((info) => info.keyType === c.stringType);
2398
+ let result = -1 /* Ternary.True */;
2399
+ for (const targetInfo of indexInfos) {
2400
+ let related;
2401
+ if (this.relation !== c.strictSubtypeRelation &&
2402
+ !sourceIsPrimitive &&
2403
+ targetHasStringIndex &&
2404
+ (targetInfo.valueType.flags & 1 /* TypeFlags.Any */) !== 0)
2405
+ related = -1 /* Ternary.True */;
2406
+ else if (isGenericMappedType(c, source) && targetHasStringIndex)
2407
+ related = this.isRelatedTo(getTemplateTypeFromMappedType(c, source), targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors);
2408
+ else
2409
+ related = this.typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
2410
+ if (related === 0 /* Ternary.False */)
2411
+ return 0 /* Ternary.False */;
2412
+ result &= related;
2413
+ }
2414
+ return result;
2415
+ }
2416
+ typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState) {
2417
+ const c = this.c;
2418
+ const sourceInfo = getApplicableIndexInfo(c, source, targetInfo.keyType);
2419
+ if (sourceInfo !== undefined)
2420
+ return this.indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors, intersectionState);
2421
+ // Intersection constituents never have inferred index signatures; under strict subtype only fresh literals do.
2422
+ if ((intersectionState & 1 /* IntersectionState.Source */) === 0 &&
2423
+ (this.relation !== c.strictSubtypeRelation || (source.objectFlags & 8192 /* ObjectFlags.FreshLiteral */) !== 0) &&
2424
+ isObjectTypeWithInferableIndex(c, source))
2425
+ return this.membersRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
2426
+ if (reportErrors)
2427
+ this.reportError(507 /* Diagnostics.Index_signature_for_type_0_is_missing_in_type_1 */, [
2428
+ typeToString(c, targetInfo.keyType),
2429
+ typeToString(c, source),
2430
+ ]);
2431
+ return 0 /* Ternary.False */;
2432
+ }
2433
+ membersRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState) {
2434
+ const c = this.c;
2435
+ let result = -1 /* Ternary.True */;
2436
+ const keyType = targetInfo.keyType;
2437
+ const props = (source.flags & 268435456 /* TypeFlags.Intersection */) !== 0
2438
+ ? getPropertiesOfUnionOrIntersectionType(c, source)
2439
+ : getPropertiesOfObjectType(c, source);
2440
+ for (const prop of props) {
2441
+ if (isIgnoredJsxProperty(source, prop))
2442
+ continue;
2443
+ if (!isApplicableIndexType(c, getLiteralTypeFromPropertyLazy(c, prop, 19456 /* TypeFlags.StringOrNumberLiteralOrUnique */, false), keyType))
2444
+ continue;
2445
+ const propType = getNonMissingTypeOfSymbol(c, prop);
2446
+ const t = c.exactOptionalPropertyTypes ||
2447
+ (propType.flags & 4 /* TypeFlags.Undefined */) !== 0 ||
2448
+ keyType === c.numberType ||
2449
+ (prop.flags & 16777216 /* SymbolFlags.Optional */) === 0
2450
+ ? propType
2451
+ : filterType(c, propType, (u) => (u.flags & 4 /* TypeFlags.Undefined */) === 0);
2452
+ const related = this.isRelatedToEx(t, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
2453
+ if (related === 0 /* Ternary.False */) {
2454
+ if (reportErrors)
2455
+ this.reportError(688 /* Diagnostics.Property_0_is_incompatible_with_index_signature */, [symbolToString(c, prop)]);
2456
+ return 0 /* Ternary.False */;
2457
+ }
2458
+ result &= related;
2459
+ }
2460
+ for (const info of getIndexInfosOfType(c, source)) {
2461
+ if (isApplicableIndexType(c, info.keyType, keyType)) {
2462
+ const related = this.indexInfoRelatedTo(info, targetInfo, reportErrors, intersectionState);
2463
+ if (related === 0 /* Ternary.False */)
2464
+ return 0 /* Ternary.False */;
2465
+ result &= related;
2466
+ }
2467
+ }
2468
+ return result;
2469
+ }
2470
+ indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors, intersectionState) {
2471
+ const c = this.c;
2472
+ const related = this.isRelatedToEx(sourceInfo.valueType, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
2473
+ if (related === 0 /* Ternary.False */ && reportErrors) {
2474
+ if (sourceInfo.keyType === targetInfo.keyType)
2475
+ this.reportError(777 /* Diagnostics.X_0_index_signatures_are_incompatible */, [typeToString(c, sourceInfo.keyType)]);
2476
+ else
2477
+ this.reportError(508 /* Diagnostics.X_0_and_1_index_signatures_are_incompatible */, [
2478
+ typeToString(c, sourceInfo.keyType),
2479
+ typeToString(c, targetInfo.keyType),
2480
+ ]);
2481
+ }
2482
+ return related;
2483
+ }
2484
+ indexSignaturesIdenticalTo(source, target) {
2485
+ const c = this.c;
2486
+ const sourceInfos = getIndexInfosOfType(c, source);
2487
+ const targetInfos = getIndexInfosOfType(c, target);
2488
+ if (sourceInfos.length !== targetInfos.length)
2489
+ return 0 /* Ternary.False */;
2490
+ for (const targetInfo of targetInfos) {
2491
+ const sourceInfo = getIndexInfoOfType(c, source, targetInfo.keyType);
2492
+ if (!(sourceInfo !== undefined &&
2493
+ this.isRelatedTo(sourceInfo.valueType, targetInfo.valueType, 3 /* RecursionFlags.Both */, false) !== 0 /* Ternary.False */ &&
2494
+ sourceInfo.isReadonly === targetInfo.isReadonly))
2495
+ return 0 /* Ternary.False */;
2496
+ }
2497
+ return -1 /* Ternary.True */;
2498
+ }
2499
+ // ---- Error reporting
2500
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
2501
+ const c = this.c;
2502
+ if (originalSource.alias !== undefined || getSingleBaseForNonAugmentingSubtype(c, originalSource) !== undefined)
2503
+ source = originalSource;
2504
+ if (originalTarget.alias !== undefined || getSingleBaseForNonAugmentingSubtype(c, originalTarget) !== undefined)
2505
+ target = originalTarget;
2506
+ if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 1048576 /* TypeFlags.Object */) !== 0)
2507
+ this.tryElaborateArrayLikeErrors(source, target, true);
2508
+ if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 12713980 /* TypeFlags.Primitive */) !== 0)
2509
+ this.tryElaborateErrorsForPrimitivesAndObjects(source, target);
2510
+ else if (source.symbol !== undefined && (source.flags & 1048576 /* TypeFlags.Object */) !== 0 && c.globalObjectType === source)
2511
+ this.reportError(828 /* Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead */, []);
2512
+ else if ((source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0 && (target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
2513
+ // Attributes failing JSX.IntrinsicAttributes or JSX.IntrinsicClassAttributes report that member's error alone.
2514
+ const targetTypes = typesOf(target);
2515
+ const errorNode = this.errorNode;
2516
+ const intrinsicAttributes = getJsxType(c, 'IntrinsicAttributes', errorNode);
2517
+ const intrinsicClassAttributes = getJsxType(c, 'IntrinsicClassAttributes', errorNode);
2518
+ if (!isErrorType(c, intrinsicAttributes) &&
2519
+ !isErrorType(c, intrinsicClassAttributes) &&
2520
+ (targetTypes.includes(intrinsicAttributes) || targetTypes.includes(intrinsicClassAttributes)))
2521
+ return;
2522
+ }
2523
+ else if ((originalTarget.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
2524
+ (lazyObjectFlags(c, originalTarget) & 67108864 /* ObjectFlags.IsNeverIntersection */) !== 0) {
2525
+ const props = getPropertiesOfUnionOrIntersectionType(c, originalTarget);
2526
+ let message = 1848 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents */;
2527
+ let prop;
2528
+ for (const p of props) {
2529
+ if (isDiscriminantWithNeverType(c, p)) {
2530
+ prop = p;
2531
+ break;
2532
+ }
2533
+ }
2534
+ if (prop === undefined) {
2535
+ message =
2536
+ 1849 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some */;
2537
+ for (const p of props) {
2538
+ if (isConflictingPrivateProperty(p)) {
2539
+ prop = p;
2540
+ break;
2541
+ }
2542
+ }
2543
+ }
2544
+ if (prop !== undefined)
2545
+ this.reportError(message, [typeToString(c, originalTarget, undefined, 1 << 29), symbolToString(c, prop)]);
2546
+ }
2547
+ this.reportRelationError(headMessage, source, target);
2548
+ if ((source.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 &&
2549
+ source.symbol !== undefined &&
2550
+ source.symbol.declarations.length !== 0 &&
2551
+ getConstraintOfType(c, source) === undefined) {
2552
+ const syntheticParam = cloneTypeParameter(c, source);
2553
+ syntheticParam.constraint = instantiateType(c, target, new SimpleTypeMapper(source, syntheticParam));
2554
+ if (hasNonCircularBaseConstraint(c, syntheticParam)) {
2555
+ this.relatedInfo.push(createDiagnosticForNode(source.symbol.declarations[0], 473 /* Diagnostics.This_type_parameter_might_need_an_extends_0_constraint */, [typeToString(c, target)]));
2556
+ }
2557
+ }
2558
+ }
2559
+ tryElaborateErrorsForPrimitivesAndObjects(source, target) {
2560
+ const c = this.c;
2561
+ if ((source === c.globalStringType && target === c.stringType) ||
2562
+ (source === c.globalNumberType && target === c.numberType) ||
2563
+ (source === c.globalBooleanType && target === c.booleanType))
2564
+ this.reportError(824 /* Diagnostics.X_0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible */, [
2565
+ typeToString(c, target),
2566
+ typeToString(c, source),
2567
+ ]);
2568
+ }
2569
+ reportRelationError(message, source, target) {
2570
+ const c = this.c;
2571
+ const names = getTypeNamesForErrorDisplay(c, source, target);
2572
+ const sourceType = names[0];
2573
+ const targetType = names[1];
2574
+ let generalizedSourceType = sourceType;
2575
+ let generalizedSource = source;
2576
+ // `never` targets keep the literal, for assertNever.
2577
+ if ((target.flags & 262144 /* TypeFlags.Never */) === 0 &&
2578
+ isLiteralType(source) &&
2579
+ !typeCouldHaveTopLevelSingletonTypes(c, target)) {
2580
+ generalizedSource = getBaseTypeOfLiteralType(c, source);
2581
+ generalizedSourceType = typeToString(c, generalizedSource, undefined, 1 << 6);
2582
+ }
2583
+ const targetFlags = (target.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0 && (source.flags & 33554432 /* TypeFlags.IndexedAccess */) === 0
2584
+ ? target.objectType.flags
2585
+ : target.flags;
2586
+ if ((targetFlags & 524288 /* TypeFlags.TypeParameter */) !== 0 &&
2587
+ target !== c.markerSuperTypeForCheck &&
2588
+ target !== c.markerSubTypeForCheck) {
2589
+ const constraint = getBaseConstraintOfType(c, target);
2590
+ if (constraint !== undefined && isTypeAssignableTo(c, generalizedSource, constraint))
2591
+ this.reportError(1150 /* Diagnostics.X_0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2 */, [generalizedSourceType, targetType, typeToString(c, constraint)]);
2592
+ else if (constraint !== undefined && isTypeAssignableTo(c, source, constraint))
2593
+ this.reportError(1150 /* Diagnostics.X_0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2 */, [sourceType, targetType, typeToString(c, constraint)]);
2594
+ else {
2595
+ // Reported once.
2596
+ this.errorChain = undefined;
2597
+ this.reportError(1157 /* Diagnostics.X_0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1 */, [
2598
+ targetType,
2599
+ generalizedSourceType,
2600
+ ]);
2601
+ }
2602
+ }
2603
+ if (message === undefined) {
2604
+ if (this.relation === c.comparableRelation)
2605
+ message = 812 /* Diagnostics.Type_0_is_not_comparable_to_type_1 */;
2606
+ else if (sourceType === targetType)
2607
+ message =
2608
+ 851 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated */;
2609
+ else if (c.exactOptionalPropertyTypes && getExactOptionalUnassignableProperties(c, source, target).length !== 0)
2610
+ message =
2611
+ 549 /* Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties */;
2612
+ else {
2613
+ if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
2614
+ const suggested = getSuggestedTypeForNonexistentStringLiteralType(c, source, target);
2615
+ if (suggested !== undefined) {
2616
+ this.reportError(951 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Did_you_mean_2 */, [
2617
+ generalizedSourceType,
2618
+ targetType,
2619
+ typeToString(c, suggested),
2620
+ ]);
2621
+ return;
2622
+ }
2623
+ }
2624
+ message = 500 /* Diagnostics.Type_0_is_not_assignable_to_type_1 */;
2625
+ }
2626
+ }
2627
+ else if (message === 521 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 */ &&
2628
+ c.exactOptionalPropertyTypes &&
2629
+ getExactOptionalUnassignableProperties(c, source, target).length !== 0)
2630
+ message =
2631
+ 553 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties */;
2632
+ switch (this.getChainMessage(0)) {
2633
+ // Suppressed after an excess property error.
2634
+ case 529 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */:
2635
+ case 715 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */:
2636
+ return;
2637
+ case 979 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */:
2638
+ case 499 /* Diagnostics.Excessive_stack_depth_comparing_types_0_and_1 */:
2639
+ case 1090 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */:
2640
+ if (this.chainArgsMatch(generalizedSourceType, targetType, undefined))
2641
+ return;
2642
+ break;
2643
+ case 873 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */:
2644
+ if (!isConversionOrInterfaceImplementationMessage(message) &&
2645
+ this.chainArgsMatch(undefined, generalizedSourceType, targetType))
2646
+ return;
2647
+ break;
2648
+ case 872 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more */:
2649
+ case 871 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2 */:
2650
+ if (!isConversionOrInterfaceImplementationMessage(message) &&
2651
+ this.chainArgsMatch(generalizedSourceType, targetType, undefined))
2652
+ return;
2653
+ break;
2654
+ }
2655
+ this.reportError(message, [generalizedSourceType, targetType]);
2656
+ }
2657
+ reportError(message, args) {
2658
+ if (message === 504 /* Diagnostics.Types_of_property_0_are_incompatible */) {
2659
+ switch (this.getChainMessage(0)) {
2660
+ case 529 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */:
2661
+ case 715 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */:
2662
+ return;
2663
+ }
2664
+ // A property followed by a return type incompatibility becomes one message for `x()`.
2665
+ let arg = '';
2666
+ switch (this.getChainMessage(1)) {
2667
+ case 469 /* Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
2668
+ arg = getPropertyNameArg(args[0]) + '()';
2669
+ break;
2670
+ case 470 /* Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
2671
+ arg = 'new ' + getPropertyNameArg(args[0]) + '()';
2672
+ break;
2673
+ case 467 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */:
2674
+ arg = getPropertyNameArg(args[0]) + '(...)';
2675
+ break;
2676
+ case 468 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */:
2677
+ arg = 'new ' + getPropertyNameArg(args[0]) + '(...)';
2678
+ break;
2679
+ }
2680
+ if (arg !== '') {
2681
+ message = 466 /* Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types */;
2682
+ args = [arg];
2683
+ this.errorChain = this.errorChain.next.next;
2684
+ }
2685
+ // Nested property incompatibilities become one message for `x.y`.
2686
+ switch (this.getChainMessage(1)) {
2687
+ case 504 /* Diagnostics.Types_of_property_0_are_incompatible */:
2688
+ case 465 /* Diagnostics.The_types_of_0_are_incompatible_between_these_types */:
2689
+ case 466 /* Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types */: {
2690
+ const head = getPropertyNameArg(args[0]);
2691
+ const tail = getPropertyNameArg(this.errorChain.next.args[0]);
2692
+ const dotted = addToDottedName(head, tail);
2693
+ this.errorChain = this.errorChain.next.next;
2694
+ if (message === 504 /* Diagnostics.Types_of_property_0_are_incompatible */)
2695
+ message = 465 /* Diagnostics.The_types_of_0_are_incompatible_between_these_types */;
2696
+ this.reportError(message, [dotted]);
2697
+ return;
2698
+ }
2699
+ }
2700
+ }
2701
+ this.errorChain = new ErrorChain(this.errorChain, message, args);
2702
+ }
2703
+ getChainMessage(index) {
2704
+ let e = this.errorChain;
2705
+ while (e !== undefined) {
2706
+ if (index === 0)
2707
+ return e.message;
2708
+ e = e.next;
2709
+ index--;
2710
+ }
2711
+ return undefined;
2712
+ }
2713
+ /** Whether the head's arguments match, with undefined as a wildcard. */
2714
+ chainArgsMatch(a0, a1, a2) {
2715
+ const args = this.errorChain.args;
2716
+ return ((a0 === undefined || args[0] === a0) &&
2717
+ (a1 === undefined || args[1] === a1) &&
2718
+ (a2 === undefined || args[2] === a2));
2719
+ }
2720
+ }
2721
+ function visibilityToString(flags) {
2722
+ if (flags === 2 /* ModifierFlags.Private */)
2723
+ return 'private';
2724
+ if (flags === 4 /* ModifierFlags.Protected */)
2725
+ return 'protected';
2726
+ return 'public';
2727
+ }
2728
+ // ---- Helpers
2729
+ export function getNormalizedType(c, t, writing) {
2730
+ for (;;) {
2731
+ let n;
2732
+ if (isFreshLiteralType(t))
2733
+ n = t.regularType;
2734
+ else if (isGenericTupleType(t))
2735
+ n = getNormalizedTupleType(c, t, writing);
2736
+ else if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && (t.flags & 1048576 /* TypeFlags.Object */) !== 0)
2737
+ n =
2738
+ t.node !== undefined
2739
+ ? createTypeReference(c, t.target, getTypeArguments(c, t))
2740
+ : (getSingleBaseForNonAugmentingSubtype(c, t) ?? t);
2741
+ else if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
2742
+ n = getNormalizedUnionOrIntersectionType(c, t, writing);
2743
+ else if ((t.flags & 16777216 /* TypeFlags.Substitution */) !== 0)
2744
+ n = writing ? t.baseType : getSubstitutionIntersection(c, t);
2745
+ else if ((t.flags & 102760448 /* TypeFlags.Simplifiable */) !== 0)
2746
+ n = getSimplifiedType(c, t, writing);
2747
+ else
2748
+ return t;
2749
+ if (n === t)
2750
+ return n;
2751
+ t = n;
2752
+ }
2753
+ }
2754
+ /** The one base of a class or interface reference that declares no members of its own, which it relates as. */
2755
+ export function getSingleBaseForNonAugmentingSubtype(c, t) {
2756
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0 || (t.flags & 1048576 /* TypeFlags.Object */) === 0)
2757
+ return undefined;
2758
+ const reference = t;
2759
+ if ((reference.target.objectFlags & 3 /* ObjectFlags.ClassOrInterface */) === 0)
2760
+ return undefined;
2761
+ const target = reference.target;
2762
+ const key = cachedTypeKey(3 /* CachedTypeKind.EquivalentBaseType */, t.id);
2763
+ const side = sideOf(c, t);
2764
+ if ((side.objectFlags & 134217728 /* ObjectFlags.IdenticalBaseTypeCalculated */) !== 0)
2765
+ return c.cachedTypesById.get(key);
2766
+ side.objectFlags |= 134217728 /* ObjectFlags.IdenticalBaseTypeCalculated */;
2767
+ if ((target.objectFlags & 1 /* ObjectFlags.Class */) !== 0) {
2768
+ // Only base types named by simple qualified names; others may refer back to the class.
2769
+ const declaration = target.symbol?.valueDeclaration;
2770
+ const baseTypeNode = declaration !== undefined ? getExtendsHeritageClauseElement(declaration) : undefined;
2771
+ if (baseTypeNode !== undefined) {
2772
+ const expression = getExpression(baseTypeNode);
2773
+ if (expression.kind !== 79 /* SyntaxKind.Identifier */ && expression.kind !== 212 /* SyntaxKind.PropertyAccessExpression */)
2774
+ return undefined;
2775
+ }
2776
+ }
2777
+ const bases = getBaseTypes(c, target);
2778
+ if (bases.length !== 1)
2779
+ return undefined;
2780
+ // Members of its own may subtype members of the base, which needs a structural comparison.
2781
+ if (t.symbol !== undefined && getMembersOfSymbol(c, t.symbol).size !== 0)
2782
+ return undefined;
2783
+ const typeParameters = target.typeParameters();
2784
+ const typeArguments = getTypeArguments(c, t);
2785
+ let instantiatedBase = typeParameters.length === 0
2786
+ ? bases[0]
2787
+ : instantiateType(c, bases[0], newTypeMapper(typeParameters.slice(), typeArguments.slice(0, typeParameters.length)));
2788
+ if (typeArguments.length > typeParameters.length)
2789
+ instantiatedBase = getTypeWithThisArgument(c, instantiatedBase, typeArguments[typeArguments.length - 1], false);
2790
+ c.cachedTypesById.set(key, instantiatedBase);
2791
+ return instantiatedBase;
2792
+ }
2793
+ function getNormalizedUnionOrIntersectionType(c, t, writing) {
2794
+ const reduced = getReducedType(c, t);
2795
+ if (reduced !== t)
2796
+ return reduced;
2797
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0 && shouldNormalizeIntersection(c, t)) {
2798
+ // Distributes `Partial<T>[K] & ({} | null)` and the like.
2799
+ const types = typesOf(t);
2800
+ let changed = false;
2801
+ const normalized = [];
2802
+ for (const u of types) {
2803
+ const n = getNormalizedType(c, u, writing);
2804
+ if (n !== u)
2805
+ changed = true;
2806
+ normalized.push(n);
2807
+ }
2808
+ if (changed)
2809
+ return getIntersectionType(c, normalized);
2810
+ }
2811
+ return t;
2812
+ }
2813
+ function shouldNormalizeIntersection(c, t) {
2814
+ let hasInstantiable = false;
2815
+ let hasNullableOrEmpty = false;
2816
+ for (const u of typesOf(t)) {
2817
+ hasInstantiable = hasInstantiable || (u.flags & 132644864 /* TypeFlags.Instantiable */) !== 0;
2818
+ hasNullableOrEmpty = hasNullableOrEmpty || (u.flags & 12 /* TypeFlags.Nullable */) !== 0 || isEmptyAnonymousObjectType(c, u);
2819
+ if (hasInstantiable && hasNullableOrEmpty)
2820
+ return true;
2821
+ }
2822
+ return false;
2823
+ }
2824
+ function getNormalizedTupleType(c, t, writing) {
2825
+ const elements = getElementTypes(c, t);
2826
+ let changed = false;
2827
+ const normalized = [];
2828
+ for (const e of elements) {
2829
+ const n = (e.flags & 102760448 /* TypeFlags.Simplifiable */) !== 0 ? getSimplifiedType(c, e, writing) : e;
2830
+ if (n !== e)
2831
+ changed = true;
2832
+ normalized.push(n);
2833
+ }
2834
+ return changed ? createNormalizedTypeReference(c, t.target, normalized) : t;
2835
+ }
2836
+ export function isWeakType(c, t) {
2837
+ if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
2838
+ const resolved = resolveStructuredTypeMembers(c, t);
2839
+ return (resolved.callSignatures.length === 0 &&
2840
+ resolved.constructSignatures.length === 0 &&
2841
+ resolved.indexInfos.length === 0 &&
2842
+ hasResolvedProperties(resolved) &&
2843
+ resolvedPropertiesAreOptional(resolved));
2844
+ }
2845
+ if ((t.flags & 16777216 /* TypeFlags.Substitution */) !== 0)
2846
+ return isWeakType(c, t.baseType);
2847
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
2848
+ for (const u of typesOf(t))
2849
+ if (!isWeakType(c, u))
2850
+ return false;
2851
+ return true;
2852
+ }
2853
+ return false;
2854
+ }
2855
+ function hasCommonProperties(c, source, target, isComparingJsxAttributes) {
2856
+ for (const prop of getPropertiesOfType(c, source))
2857
+ if (isKnownProperty(c, target, prop.name, isComparingJsxAttributes))
2858
+ return true;
2859
+ return false;
2860
+ }
2861
+ /** Whether `name` is known anywhere in `targetType`: declared, covered by an index signature, or in some constituent. */
2862
+ export function isKnownProperty(c, targetType, name, isComparingJsxAttributes) {
2863
+ if ((targetType.flags & 1048576 /* TypeFlags.Object */) !== 0) {
2864
+ if (getPropertyOfObjectType(c, targetType, name) !== undefined ||
2865
+ getApplicableIndexInfoForName(c, targetType, name) !== undefined ||
2866
+ (isLateBoundName(name) && getIndexInfoOfType(c, targetType, c.stringType) !== undefined) ||
2867
+ (isComparingJsxAttributes && name.includes('-')))
2868
+ return true;
2869
+ }
2870
+ if ((targetType.flags & 16777216 /* TypeFlags.Substitution */) !== 0)
2871
+ return isKnownProperty(c, targetType.baseType, name, isComparingJsxAttributes);
2872
+ if ((targetType.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0 && isExcessPropertyCheckTarget(targetType))
2873
+ for (const t of typesOf(targetType))
2874
+ if (isKnownProperty(c, t, name, isComparingJsxAttributes))
2875
+ return true;
2876
+ return false;
2877
+ }
2878
+ function isExcessPropertyCheckTarget(t) {
2879
+ if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0)
2880
+ return (t.objectFlags & 512 /* ObjectFlags.ObjectLiteralPatternWithComputedProperties */) === 0;
2881
+ if ((t.flags & 131072 /* TypeFlags.NonPrimitive */) !== 0)
2882
+ return true;
2883
+ if ((t.flags & 16777216 /* TypeFlags.Substitution */) !== 0)
2884
+ return isExcessPropertyCheckTarget(t.baseType);
2885
+ if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0) {
2886
+ for (const u of typesOf(t))
2887
+ if (isExcessPropertyCheckTarget(u))
2888
+ return true;
2889
+ return false;
2890
+ }
2891
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
2892
+ for (const u of typesOf(t))
2893
+ if (!isExcessPropertyCheckTarget(u))
2894
+ return false;
2895
+ return true;
2896
+ }
2897
+ return false;
2898
+ }
2899
+ function shouldCheckAsExcessProperty(prop, container) {
2900
+ return (prop.valueDeclaration !== undefined &&
2901
+ container !== undefined &&
2902
+ container.valueDeclaration !== undefined &&
2903
+ prop.valueDeclaration.parent === container.valueDeclaration);
2904
+ }
2905
+ function isIgnoredJsxProperty(source, prop) {
2906
+ return (source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0 && prop.name.includes('-');
2907
+ }
2908
+ function isObjectLiteralElement(node) {
2909
+ switch (node.kind) {
2910
+ case 303 /* SyntaxKind.PropertyAssignment */:
2911
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
2912
+ case 305 /* SyntaxKind.SpreadAssignment */:
2913
+ case 175 /* SyntaxKind.MethodDeclaration */:
2914
+ case 178 /* SyntaxKind.GetAccessor */:
2915
+ case 179 /* SyntaxKind.SetAccessor */:
2916
+ return true;
2917
+ }
2918
+ return false;
2919
+ }
2920
+ function isAncestor(node, ancestor) {
2921
+ for (let n = node; n !== undefined; n = n.parent)
2922
+ if (n === ancestor)
2923
+ return true;
2924
+ return false;
2925
+ }
2926
+ function rootOf(node) {
2927
+ let n = node;
2928
+ while (n.parent !== undefined)
2929
+ n = n.parent;
2930
+ return n;
2931
+ }
2932
+ function sameFile(a, b) {
2933
+ return b !== undefined && rootOf(a) === rootOf(b);
2934
+ }
2935
+ export function isTypeSubsetOf(c, source, target) {
2936
+ return (source === target ||
2937
+ (source.flags & 262144 /* TypeFlags.Never */) !== 0 ||
2938
+ ((target.flags & 134217728 /* TypeFlags.Union */) !== 0 && isTypeSubsetOfUnion(c, source, target)));
2939
+ }
2940
+ function isTypeSubsetOfUnion(c, source, target) {
2941
+ const union = target;
2942
+ if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0)
2943
+ return unionContainsSortedTypes(c, union, typesOf(source));
2944
+ if ((source.flags & 98304 /* TypeFlags.EnumLike */) !== 0 && getBaseTypeOfEnumLikeType(c, source) === target)
2945
+ return true;
2946
+ return unionContainsType(c, union, source);
2947
+ }
2948
+ function getTypeOfPropertyInTypes(c, types, name) {
2949
+ const propTypes = [];
2950
+ for (const t of types)
2951
+ propTypes.push(getTypeOfPropertyInType(c, t, name));
2952
+ return getUnionType(c, propTypes);
2953
+ }
2954
+ function getTypeOfPropertyInType(c, t, name) {
2955
+ t = getApparentType(c, t);
2956
+ const prop = (t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0
2957
+ ? getPropertyOfUnionOrIntersectionType(c, t, name, false)
2958
+ : getPropertyOfObjectType(c, t, name);
2959
+ if (prop !== undefined)
2960
+ return getTypeOfSymbol(c, prop);
2961
+ const indexInfo = getApplicableIndexInfoForName(c, t, name);
2962
+ return indexInfo !== undefined ? indexInfo.valueType : c.undefinedType;
2963
+ }
2964
+ export function getRegularTypeOfObjectLiteral(c, t) {
2965
+ return getRegularTypeOfObjectLiteralLazy(c, t);
2966
+ }
2967
+ import { getRegularTypeOfObjectLiteral as getRegularTypeOfObjectLiteralLazy, getLiteralTypeFromPropertyForRelations as getLiteralTypeFromPropertyLazy, } from './checker-literals.js';
2968
+ function filterPrimitivesIfContainsNonPrimitive(c, t) {
2969
+ if (typesOf(t).some((u) => (u.flags & 131072 /* TypeFlags.NonPrimitive */) !== 0)) {
2970
+ const result = filterType(c, t, (u) => (u.flags & 12713980 /* TypeFlags.Primitive */) === 0);
2971
+ if ((result.flags & 262144 /* TypeFlags.Never */) === 0)
2972
+ return result;
2973
+ }
2974
+ return t;
2975
+ }
2976
+ function findMatchingDiscriminantType(c, source, target, relater) {
2977
+ if ((target.flags & 134217728 /* TypeFlags.Union */) === 0 || (source.flags & (268435456 /* TypeFlags.Intersection */ | 1048576 /* TypeFlags.Object */)) === 0)
2978
+ return undefined;
2979
+ const match = getMatchingUnionConstituentForType(c, target, source);
2980
+ if (match !== undefined)
2981
+ return match;
2982
+ const discriminants = [];
2983
+ for (const p of getPropertiesOfType(c, source))
2984
+ if (isDiscriminantProperty(c, target, p.name))
2985
+ discriminants.push(p);
2986
+ if (discriminants.length === 0)
2987
+ return undefined;
2988
+ const discriminated = discriminateTypeByDiscriminants(c, target, discriminants, relater);
2989
+ return discriminated !== target ? discriminated : undefined;
2990
+ }
2991
+ /**
2992
+ * The constituents of the union `target` whose types of each discriminant property the source's
2993
+ * values relate to (discriminateTypeByDiscriminableItems). Primitive and never constituents are left
2994
+ * out. A discriminant that no remaining constituent matches is ignored, so the result is never empty.
2995
+ */
2996
+ function discriminateTypeByDiscriminants(c, target, discriminants, relater) {
2997
+ const types = typesOf(target);
2998
+ const include = [];
2999
+ for (const t of types)
3000
+ include.push((t.flags & 12713980 /* TypeFlags.Primitive */) === 0 && (getReducedType(c, t).flags & 262144 /* TypeFlags.Never */) === 0
3001
+ ? -1 /* Ternary.True */
3002
+ : 0 /* Ternary.False */);
3003
+ for (const prop of discriminants) {
3004
+ let matched = false;
3005
+ for (let i = 0; i < types.length; i++) {
3006
+ if (include[i] === 0 /* Ternary.False */)
3007
+ continue;
3008
+ const targetType = getTypeOfPropertyOrIndexSignatureOfType(c, types[i], prop.name);
3009
+ if (targetType === undefined)
3010
+ continue;
3011
+ if (someType(getTypeOfSymbol(c, prop), (s) => relater.isRelatedToSimple(s, targetType) !== 0 /* Ternary.False */))
3012
+ matched = true;
3013
+ else
3014
+ include[i] = 3 /* Ternary.Maybe */;
3015
+ }
3016
+ // Without a match the discriminant is ignored.
3017
+ for (let i = 0; i < types.length; i++)
3018
+ if (include[i] === 3 /* Ternary.Maybe */)
3019
+ include[i] = matched ? 0 /* Ternary.False */ : -1 /* Ternary.True */;
3020
+ }
3021
+ if (!include.includes(0 /* Ternary.False */))
3022
+ return target;
3023
+ const filtered = [];
3024
+ for (let i = 0; i < types.length; i++)
3025
+ if (include[i] === -1 /* Ternary.True */)
3026
+ filtered.push(types[i]);
3027
+ const result = getUnionTypeEx(c, filtered, 0 /* UnionReduction.None */, undefined, undefined);
3028
+ return (result.flags & 262144 /* TypeFlags.Never */) === 0 ? result : target;
3029
+ }
3030
+ function getTypeOfPropertyOrIndexSignatureOfType(c, t, name) {
3031
+ const propType = getTypeOfPropertyOfType(c, t, name);
3032
+ if (propType !== undefined)
3033
+ return propType;
3034
+ const info = getApplicableIndexInfoForName(c, t, name);
3035
+ return info !== undefined ? getOptionalType(c, info.valueType, true) : undefined;
3036
+ }
3037
+ export function isDiscriminantProperty(c, t, name) {
3038
+ if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
3039
+ return false;
3040
+ const prop = getUnionOrIntersectionProperty(c, t, name, false);
3041
+ if (prop === undefined || (prop.checkFlags & 2 /* CheckFlags.SyntheticProperty */) === 0)
3042
+ return false;
3043
+ if ((prop.checkFlags & 2097152 /* CheckFlags.IsDiscriminantComputed */) === 0) {
3044
+ prop.checkFlags |= 2097152 /* CheckFlags.IsDiscriminantComputed */;
3045
+ if ((prop.checkFlags & 192 /* CheckFlags.NonUniformAndLiteral */) === 192 /* CheckFlags.NonUniformAndLiteral */ &&
3046
+ !isGenericTypeLocal(c, getTypeOfSymbol(c, prop)))
3047
+ prop.checkFlags |= 4194304 /* CheckFlags.IsDiscriminant */;
3048
+ }
3049
+ return (prop.checkFlags & 4194304 /* CheckFlags.IsDiscriminant */) !== 0;
3050
+ }
3051
+ import { isGenericType as isGenericTypeLocal } from './checker-type-operators.js';
3052
+ /** The constituent selected by a key property's unit type; not computed yet. */
3053
+ export function getMatchingUnionConstituentForType(_c, _unionType, _t) {
3054
+ return undefined;
3055
+ }
3056
+ /** The constituent of the union `target` that `source` most likely meant, for error elaboration. */
3057
+ export function getBestMatchingTypeForElaboration(c, source, target) {
3058
+ return getBestMatchingType(c, source, target, new Relater(c, c.assignableRelation, undefined));
3059
+ }
3060
+ function getBestMatchingType(c, source, target, relater) {
3061
+ return (findMatchingDiscriminantType(c, source, target, relater) ??
3062
+ findMatchingTypeReferenceOrTypeAliasReference(source, target) ??
3063
+ findBestTypeForObjectLiteral(c, source, target) ??
3064
+ findBestTypeForInvokable(c, source, target, 0 /* SignatureKind.Call */) ??
3065
+ findBestTypeForInvokable(c, source, target, 1 /* SignatureKind.Construct */) ??
3066
+ findMostOverlappyType(c, source, target));
3067
+ }
3068
+ function findMatchingTypeReferenceOrTypeAliasReference(source, unionTarget) {
3069
+ const sourceObjectFlags = source.objectFlags;
3070
+ if ((sourceObjectFlags & (4 /* ObjectFlags.Reference */ | 16 /* ObjectFlags.Anonymous */)) === 0 ||
3071
+ (source.flags & 1048576 /* TypeFlags.Object */) === 0 ||
3072
+ (unionTarget.flags & 134217728 /* TypeFlags.Union */) === 0)
3073
+ return undefined;
3074
+ for (const target of typesOf(unionTarget)) {
3075
+ if ((target.flags & 1048576 /* TypeFlags.Object */) === 0)
3076
+ continue;
3077
+ const overlap = sourceObjectFlags & target.objectFlags;
3078
+ if ((overlap & 4 /* ObjectFlags.Reference */) !== 0 &&
3079
+ source.target === target.target)
3080
+ return target;
3081
+ if ((overlap & 16 /* ObjectFlags.Anonymous */) !== 0 &&
3082
+ source.alias !== undefined &&
3083
+ target.alias !== undefined &&
3084
+ source.alias.symbol === target.alias.symbol)
3085
+ return target;
3086
+ }
3087
+ return undefined;
3088
+ }
3089
+ function findBestTypeForInvokable(c, source, unionTarget, kind) {
3090
+ if (getSignaturesOfType(c, source, kind).length === 0)
3091
+ return undefined;
3092
+ for (const t of typesOf(unionTarget))
3093
+ if (getSignaturesOfType(c, t, kind).length !== 0)
3094
+ return t;
3095
+ return undefined;
3096
+ }
3097
+ function findMostOverlappyType(c, source, unionTarget) {
3098
+ if ((source.flags & (12713980 /* TypeFlags.Primitive */ | 14680064 /* TypeFlags.InstantiablePrimitive */)) !== 0)
3099
+ return undefined;
3100
+ let bestMatch;
3101
+ let matchingCount = 0;
3102
+ for (const target of typesOf(unionTarget)) {
3103
+ if ((target.flags & (12713980 /* TypeFlags.Primitive */ | 14680064 /* TypeFlags.InstantiablePrimitive */)) !== 0)
3104
+ continue;
3105
+ const overlap = getIntersectionType(c, [getIndexType(c, source), getIndexType(c, target)]);
3106
+ if ((overlap.flags & 2097152 /* TypeFlags.Index */) !== 0)
3107
+ return target;
3108
+ if (isUnitType(overlap) || (overlap.flags & 134217728 /* TypeFlags.Union */) !== 0) {
3109
+ const length = (overlap.flags & 134217728 /* TypeFlags.Union */) !== 0 ? countUnitTypes(typesOf(overlap)) : 1;
3110
+ if (length >= matchingCount) {
3111
+ bestMatch = target;
3112
+ matchingCount = length;
3113
+ }
3114
+ }
3115
+ }
3116
+ return bestMatch;
3117
+ }
3118
+ function symbolNames(c, symbols) {
3119
+ const names = [];
3120
+ for (const s of symbols)
3121
+ names.push(symbolToString(c, s));
3122
+ return names.join(', ');
3123
+ }
3124
+ function countUnitTypes(types) {
3125
+ let count = 0;
3126
+ for (const t of types)
3127
+ if (isUnitType(t))
3128
+ count++;
3129
+ return count;
3130
+ }
3131
+ function findBestTypeForObjectLiteral(c, source, unionTarget) {
3132
+ if ((source.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0 && someType(unionTarget, (t) => isArrayLikeType(c, t)))
3133
+ for (const t of typesOf(unionTarget))
3134
+ if (!isArrayLikeType(c, t))
3135
+ return t;
3136
+ return undefined;
3137
+ }
3138
+ function shouldReportUnmatchedPropertyError(c, source, target) {
3139
+ const calls = getSignaturesOfStructuredType(c, source, 0 /* SignatureKind.Call */);
3140
+ const constructs = getSignaturesOfStructuredType(c, source, 1 /* SignatureKind.Construct */);
3141
+ const properties = getPropertiesOfObjectType(c, source);
3142
+ if ((calls.length !== 0 || constructs.length !== 0) && properties.length === 0)
3143
+ return ((getSignaturesOfType(c, target, 0 /* SignatureKind.Call */).length !== 0 && calls.length !== 0) ||
3144
+ (getSignaturesOfType(c, target, 1 /* SignatureKind.Construct */).length !== 0 && constructs.length !== 0));
3145
+ return true;
3146
+ }
3147
+ function isStaticPrivateIdentifierProperty(prop) {
3148
+ const d = prop.valueDeclaration;
3149
+ if (d === undefined)
3150
+ return false;
3151
+ const name = getName(d);
3152
+ return (name !== undefined &&
3153
+ name.kind === 80 /* SyntaxKind.PrivateIdentifier */ &&
3154
+ (getCombinedModifierFlags(d) & 256 /* ModifierFlags.Static */) !== 0);
3155
+ }
3156
+ export function getUnmatchedProperty(c, source, target, requireOptionalProperties, matchDiscriminantProperties) {
3157
+ for (const targetProp of getPropertiesOfType(c, target))
3158
+ if (isUnmatchedProperty(c, source, targetProp, requireOptionalProperties, matchDiscriminantProperties))
3159
+ return targetProp;
3160
+ return undefined;
3161
+ }
3162
+ /** Whether `getUnmatchedProperty` reports `targetProp`, a property of the target. */
3163
+ export function isUnmatchedProperty(c, source, targetProp, requireOptionalProperties, matchDiscriminantProperties) {
3164
+ if (isStaticPrivateIdentifierProperty(targetProp))
3165
+ return false;
3166
+ if (!requireOptionalProperties &&
3167
+ ((targetProp.flags & 16777216 /* SymbolFlags.Optional */) !== 0 || (targetProp.checkFlags & 48 /* CheckFlags.Partial */) !== 0))
3168
+ return false;
3169
+ const sourceProp = getPropertyOfType(c, source, targetProp.name);
3170
+ if (sourceProp === undefined)
3171
+ return true;
3172
+ if (!matchDiscriminantProperties)
3173
+ return false;
3174
+ // A unit-typed (discriminant) property whose literal differs in the source is unmatched.
3175
+ const targetType = getTypeOfSymbol(c, targetProp);
3176
+ if ((targetType.flags & 97292 /* TypeFlags.Unit */) === 0)
3177
+ return false;
3178
+ const sourceType = getTypeOfSymbol(c, sourceProp);
3179
+ return !((sourceType.flags & 1 /* TypeFlags.Any */) !== 0 ||
3180
+ getRegularTypeOfLiteralType(c, sourceType) === getRegularTypeOfLiteralType(c, targetType));
3181
+ }
3182
+ export function getUnmatchedProperties(c, source, target, requireOptionalProperties) {
3183
+ const result = [];
3184
+ for (const targetProp of getPropertiesOfType(c, target)) {
3185
+ if (isStaticPrivateIdentifierProperty(targetProp))
3186
+ continue;
3187
+ if (requireOptionalProperties ||
3188
+ ((targetProp.flags & 16777216 /* SymbolFlags.Optional */) === 0 && (targetProp.checkFlags & 48 /* CheckFlags.Partial */) === 0))
3189
+ if (getPropertyOfType(c, source, targetProp.name) === undefined)
3190
+ result.push(targetProp);
3191
+ }
3192
+ return result;
3193
+ }
3194
+ function getDeclaringClass(c, prop) {
3195
+ return prop.parent !== undefined && (prop.parent.flags & 32 /* SymbolFlags.Class */) !== 0
3196
+ ? getDeclaredTypeOfSymbol(c, getParentOfSymbol(c, prop))
3197
+ : undefined;
3198
+ }
3199
+ /** Whether `sourceProp`'s class derives from `targetProp`'s, for protected members. */
3200
+ /** Whether every protected constituent of `targetProp` is declared in a base of a class declaring `sourceProp`. */
3201
+ function isValidOverrideOf(c, sourceProp, targetProp) {
3202
+ return !forEachProperty(c, targetProp, (tp) => (getDeclarationModifierFlagsFromSymbol(c, tp, false) & 4 /* ModifierFlags.Protected */) !== 0 &&
3203
+ !isPropertyInClassDerivedFrom(c, sourceProp, getDeclaringClass(c, tp)));
3204
+ }
3205
+ /** Whether some underlying property of `prop` is declared in a class deriving from `baseClass`. */
3206
+ function isPropertyInClassDerivedFrom(c, prop, baseClass) {
3207
+ return forEachProperty(c, prop, (sp) => {
3208
+ const sourceClass = getDeclaringClass(c, sp);
3209
+ return sourceClass !== undefined && baseClass !== undefined && hasBaseType(c, sourceClass, baseClass);
3210
+ });
3211
+ }
3212
+ /** Calls `callback` with a property, or with the underlying properties of a synthetic one, until it returns true. */
3213
+ function forEachProperty(c, prop, callback) {
3214
+ if ((prop.checkFlags & 6 /* CheckFlags.Synthetic */) === 0)
3215
+ return callback(prop);
3216
+ const containingType = c.symbolContainingTypes.get(getSymbolId(prop));
3217
+ if (containingType === undefined)
3218
+ return false;
3219
+ for (const t of typesOf(containingType)) {
3220
+ const p = getPropertyOfType(c, t, prop.name);
3221
+ if (p !== undefined && forEachProperty(c, p, callback))
3222
+ return true;
3223
+ }
3224
+ return false;
3225
+ }
3226
+ export function isObjectTypeWithInferableIndex(c, t) {
3227
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
3228
+ for (const u of typesOf(t))
3229
+ if (!isObjectTypeWithInferableIndex(c, u))
3230
+ return false;
3231
+ return true;
3232
+ }
3233
+ return ((t.symbol !== undefined &&
3234
+ (t.symbol.flags &
3235
+ (4096 /* SymbolFlags.ObjectLiteral */ | 2048 /* SymbolFlags.TypeLiteral */ | 384 /* SymbolFlags.Enum */ | 512 /* SymbolFlags.ValueModule */)) !==
3236
+ 0 &&
3237
+ (t.symbol.flags & 32 /* SymbolFlags.Class */) === 0 &&
3238
+ !typeHasCallOrConstructSignatures(c, t)) ||
3239
+ (t.objectFlags & (4096 /* ObjectFlags.JSLiteral */ | 8388608 /* ObjectFlags.ObjectRestType */)) !== 0 ||
3240
+ // A reverse mapped type has an inferable index when its source does.
3241
+ ((t.objectFlags & 1024 /* ObjectFlags.ReverseMapped */) !== 0 &&
3242
+ t.source !== undefined &&
3243
+ isObjectTypeWithInferableIndex(c, t.source)));
3244
+ }
3245
+ export function typeHasCallOrConstructSignatures(c, t) {
3246
+ if ((t.flags & 403701760 /* TypeFlags.StructuredType */) === 0)
3247
+ return false;
3248
+ const resolved = resolveStructuredTypeMembers(c, t);
3249
+ return resolved.callSignatures.length !== 0 || resolved.constructSignatures.length !== 0;
3250
+ }
3251
+ /** Both names of the pair, fully qualified when they print the same. */
3252
+ export function getTypeNamesForErrorDisplay(c, left, right) {
3253
+ // The type of an expression that isn't context sensitive prints as written there.
3254
+ let leftStr = typeToString(c, left, contextFreeExpressionDeclaration(c, left));
3255
+ let rightStr = typeToString(c, right, contextFreeExpressionDeclaration(c, right));
3256
+ if (leftStr === rightStr) {
3257
+ leftStr = typeToString(c, left, undefined, 1 << 6);
3258
+ rightStr = typeToString(c, right, undefined, 1 << 6);
3259
+ }
3260
+ return [leftStr, rightStr];
3261
+ }
3262
+ function contextFreeExpressionDeclaration(c, t) {
3263
+ const declaration = t.symbol?.valueDeclaration;
3264
+ if (declaration === undefined)
3265
+ return undefined;
3266
+ switch (declaration.kind) {
3267
+ case 220 /* SyntaxKind.ArrowFunction */:
3268
+ case 219 /* SyntaxKind.FunctionExpression */:
3269
+ case 232 /* SyntaxKind.ClassExpression */:
3270
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
3271
+ case 227 /* SyntaxKind.BinaryExpression */:
3272
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
3273
+ case 213 /* SyntaxKind.ElementAccessExpression */:
3274
+ case 214 /* SyntaxKind.CallExpression */:
3275
+ return isContextSensitive(c, declaration) ? undefined : declaration;
3276
+ }
3277
+ return undefined;
3278
+ }
3279
+ function typeCouldHaveTopLevelSingletonTypes(c, t) {
3280
+ if ((t.flags & 256 /* TypeFlags.Boolean */) !== 0)
3281
+ return false;
3282
+ if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
3283
+ for (const u of typesOf(t))
3284
+ if (typeCouldHaveTopLevelSingletonTypes(c, u))
3285
+ return true;
3286
+ return false;
3287
+ }
3288
+ if ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0) {
3289
+ const constraint = getConstraintOfType(c, t);
3290
+ if (constraint !== undefined && constraint !== t)
3291
+ return typeCouldHaveTopLevelSingletonTypes(c, constraint);
3292
+ }
3293
+ return isUnitType(t) || (t.flags & (4194304 /* TypeFlags.TemplateLiteral */ | 8388608 /* TypeFlags.StringMapping */)) !== 0;
3294
+ }
3295
+ /**
3296
+ * Puts `t` at `stack[depth]`. Recursion stacks keep their entries from `depth` on as stale slots,
3297
+ * which avoids releasing an entry on every pop.
3298
+ */
3299
+ export function setStackEntry(stack, depth, t) {
3300
+ if (depth < stack.length)
3301
+ stack[depth] = t;
3302
+ else
3303
+ stack.push(t);
3304
+ }
3305
+ /**
3306
+ * Deeply nested: `maxDepth` or more same-identity types in `stack[0..depth)`, each newer than the
3307
+ * last.
3308
+ */
3309
+ export function isDeeplyNestedType(c, t, stack, depth, maxDepth) {
3310
+ if (depth < maxDepth)
3311
+ return false;
3312
+ if ((t.objectFlags & 96 /* ObjectFlags.InstantiatedMapped */) === 96 /* ObjectFlags.InstantiatedMapped */ &&
3313
+ (t.flags & 1048576 /* TypeFlags.Object */) !== 0)
3314
+ t = getMappedTargetWithSymbol(c, t);
3315
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
3316
+ for (const u of typesOf(t))
3317
+ if (isDeeplyNestedType(c, u, stack, depth, maxDepth))
3318
+ return true;
3319
+ const identity = getRecursionIdentity(t);
3320
+ let count = 0;
3321
+ let lastTypeId = 0;
3322
+ for (let i = 0; i < depth; i++) {
3323
+ const s = stack[i];
3324
+ if (hasMatchingRecursionIdentity(c, s, identity)) {
3325
+ if (s.id >= lastTypeId) {
3326
+ count++;
3327
+ if (count >= maxDepth)
3328
+ return true;
3329
+ }
3330
+ lastTypeId = s.id;
3331
+ }
3332
+ }
3333
+ return false;
3334
+ }
3335
+ function getMappedTargetWithSymbol(c, t) {
3336
+ for (;;) {
3337
+ if ((t.objectFlags & 96 /* ObjectFlags.InstantiatedMapped */) === 96 /* ObjectFlags.InstantiatedMapped */ &&
3338
+ (t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
3339
+ const target = getModifiersTypeFromMappedType(c, t);
3340
+ if (target.symbol !== undefined ||
3341
+ ((target.flags & 268435456 /* TypeFlags.Intersection */) !== 0 && typesOf(target).some((u) => u.symbol !== undefined))) {
3342
+ t = target;
3343
+ continue;
3344
+ }
3345
+ }
3346
+ return t;
3347
+ }
3348
+ }
3349
+ function hasMatchingRecursionIdentity(c, t, identity) {
3350
+ if ((t.objectFlags & 96 /* ObjectFlags.InstantiatedMapped */) === 96 /* ObjectFlags.InstantiatedMapped */ &&
3351
+ (t.flags & 1048576 /* TypeFlags.Object */) !== 0)
3352
+ t = getMappedTargetWithSymbol(c, t);
3353
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
3354
+ for (const u of typesOf(t))
3355
+ if (hasMatchingRecursionIdentity(c, u, identity))
3356
+ return true;
3357
+ return false;
3358
+ }
3359
+ return getRecursionIdentity(t) === identity;
3360
+ }
3361
+ /** An identity shared by instantiations of a type, so infinitely expanding instantiations can be detected. */
3362
+ export function getRecursionIdentity(t) {
3363
+ if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
3364
+ (t.objectFlags & (128 /* ObjectFlags.ObjectLiteral */ | 16384 /* ObjectFlags.ArrayLiteral */)) === 0) {
3365
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && t.node !== undefined)
3366
+ return nodeRecursionId(t.node);
3367
+ if (t.symbol !== undefined &&
3368
+ !((t.objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0 && (t.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) &&
3369
+ (t.objectFlags & 1073741824 /* ObjectFlags.FromTypeNode */) === 0)
3370
+ return symbolRecursionId(t.symbol);
3371
+ if (isTupleType(t) && (t.objectFlags & 1073741824 /* ObjectFlags.FromTypeNode */) === 0)
3372
+ return typeRecursionId(t.target);
3373
+ }
3374
+ if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && t.symbol !== undefined)
3375
+ return symbolRecursionId(t.symbol);
3376
+ if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
3377
+ let objectType = t.objectType;
3378
+ while ((objectType.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0)
3379
+ objectType = objectType.objectType;
3380
+ return typeRecursionId(objectType);
3381
+ }
3382
+ if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
3383
+ return nodeRecursionId(t.root.node);
3384
+ return typeRecursionId(t);
3385
+ }
3386
+ function nodeRecursionId(node) {
3387
+ return getNodeId(node) * 4 + 1;
3388
+ }
3389
+ function symbolRecursionId(symbol) {
3390
+ return getSymbolId(symbol) * 4 + 2;
3391
+ }
3392
+ function typeRecursionId(t) {
3393
+ return t.id * 4 + 3;
3394
+ }
3395
+ // ---- Variance
3396
+ export function isMarkerType(c, t) {
3397
+ return c.markerTypes.has(t);
3398
+ }
3399
+ export function getVariances(c, t) {
3400
+ // Arrays and tuples are covariant.
3401
+ if (t === c.globalArrayType || t === c.globalReadonlyArrayType || (t.objectFlags & 8 /* ObjectFlags.Tuple */) !== 0)
3402
+ return c.arrayVariances;
3403
+ return getVariancesWorker(c, t.symbol, t.typeParameters());
3404
+ }
3405
+ export function getAliasVariances(c, symbol) {
3406
+ return getVariancesWorker(c, symbol, c.symbolLinks(symbol).typeParameters ?? emptyTypes);
3407
+ }
3408
+ /**
3409
+ * The measured variance of each type parameter, from relating marker instantiations; empty when
3410
+ * requested recursively.
3411
+ */
3412
+ function getVariancesWorker(c, symbol, typeParameters) {
3413
+ const links = c.symbolLinks(symbol);
3414
+ if (links.variances !== undefined)
3415
+ return links.variances;
3416
+ const oldVarianceComputation = c.inVarianceComputation;
3417
+ const saveResolutionStart = c.resolutionStart;
3418
+ if (!c.inVarianceComputation) {
3419
+ c.inVarianceComputation = true;
3420
+ c.resolutionStart = c.resolutionDepth;
3421
+ }
3422
+ links.variances = [];
3423
+ const variances = [];
3424
+ for (const tp of typeParameters) {
3425
+ const modifiers = getTypeParameterModifiers(tp);
3426
+ let variance;
3427
+ if ((modifiers & 16384 /* ModifierFlags.Out */) !== 0)
3428
+ variance = (modifiers & 8192 /* ModifierFlags.In */) !== 0 ? 0 /* VarianceFlags.Invariant */ : 1 /* VarianceFlags.Covariant */;
3429
+ else if ((modifiers & 8192 /* ModifierFlags.In */) !== 0)
3430
+ variance = 2 /* VarianceFlags.Contravariant */;
3431
+ else {
3432
+ const saveReliabilityFlags = c.reliabilityFlags;
3433
+ c.reliabilityFlags = 0;
3434
+ const typeWithSuper = createMarkerType(c, symbol, tp, c.markerSuperType);
3435
+ const typeWithSub = createMarkerType(c, symbol, tp, c.markerSubType);
3436
+ variance =
3437
+ (isTypeAssignableTo(c, typeWithSub, typeWithSuper) ? 1 /* VarianceFlags.Covariant */ : 0) |
3438
+ (isTypeAssignableTo(c, typeWithSuper, typeWithSub) ? 2 /* VarianceFlags.Contravariant */ : 0);
3439
+ // Bivariance may mean the parameter is unwitnessed.
3440
+ if (variance === 3 /* VarianceFlags.Bivariant */ &&
3441
+ isTypeAssignableTo(c, createMarkerType(c, symbol, tp, c.markerOtherType), typeWithSuper))
3442
+ variance = 4 /* VarianceFlags.Independent */;
3443
+ if ((c.reliabilityFlags & 8 /* RelationComparisonResult.ReportsUnmeasurable */) !== 0)
3444
+ variance |= 8 /* VarianceFlags.Unmeasurable */;
3445
+ if ((c.reliabilityFlags & 16 /* RelationComparisonResult.ReportsUnreliable */) !== 0)
3446
+ variance |= 16 /* VarianceFlags.Unreliable */;
3447
+ c.reliabilityFlags = saveReliabilityFlags;
3448
+ }
3449
+ variances.push(variance);
3450
+ }
3451
+ if (!oldVarianceComputation) {
3452
+ c.inVarianceComputation = false;
3453
+ c.resolutionStart = saveResolutionStart;
3454
+ }
3455
+ links.variances = variances;
3456
+ return variances;
3457
+ }
3458
+ export function createMarkerType(c, symbol, source, target) {
3459
+ const mapper = new SimpleTypeMapper(source, target);
3460
+ const t = getDeclaredTypeOfSymbol(c, symbol);
3461
+ if (isErrorType(c, t))
3462
+ return t;
3463
+ const typeArguments = [];
3464
+ const typeParameters = (symbol.flags & 524288 /* SymbolFlags.TypeAlias */) !== 0
3465
+ ? (c.symbolLinks(symbol).typeParameters ?? emptyTypes)
3466
+ : t.typeParameters();
3467
+ for (const p of typeParameters)
3468
+ typeArguments.push(instantiateType(c, p, mapper));
3469
+ const result = (symbol.flags & 524288 /* SymbolFlags.TypeAlias */) !== 0
3470
+ ? getTypeAliasInstantiation(c, symbol, typeArguments, undefined)
3471
+ : createTypeReference(c, t, typeArguments);
3472
+ c.markerTypes.add(result);
3473
+ return result;
3474
+ }
3475
+ import { getTypeAliasInstantiation } from './checker-type-nodes.js';
3476
+ export function getTypeParameterModifiers(tp) {
3477
+ let flags = 0;
3478
+ if (tp.symbol !== undefined)
3479
+ for (const d of tp.symbol.declarations)
3480
+ flags |= getCombinedModifierFlags(d);
3481
+ return flags & (8192 /* ModifierFlags.In */ | 16384 /* ModifierFlags.Out */ | 4096 /* ModifierFlags.Const */);
3482
+ }
3483
+ function someVarianceHasFlags(variances, flags) {
3484
+ for (const v of variances)
3485
+ if ((v & flags) !== 0)
3486
+ return true;
3487
+ return false;
3488
+ }
3489
+ function someVarianceIsInvariant(variances) {
3490
+ for (const v of variances)
3491
+ if ((v & 7 /* VarianceFlags.VarianceMask */) === 0 /* VarianceFlags.Invariant */)
3492
+ return true;
3493
+ return false;
3494
+ }
3495
+ function hasCovariantVoidArgument(typeArguments, variances) {
3496
+ for (let i = 0; i < variances.length; i++)
3497
+ if ((variances[i] & 7 /* VarianceFlags.VarianceMask */) === 1 /* VarianceFlags.Covariant */ &&
3498
+ (typeArguments[i].flags & 16 /* TypeFlags.Void */) !== 0)
3499
+ return true;
3500
+ return false;
3501
+ }
3502
+ // ---- Misc structural helpers
3503
+ function getEffectiveConstraintOfIntersection(c, types, targetIsUnion) {
3504
+ let constraints;
3505
+ let hasDisjointDomainType = false;
3506
+ for (const t of types) {
3507
+ if ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0) {
3508
+ // Follow constraints known not to be circular.
3509
+ let constraint = getConstraintOfType(c, t);
3510
+ while (constraint !== undefined &&
3511
+ (constraint.flags & (524288 /* TypeFlags.TypeParameter */ | 2097152 /* TypeFlags.Index */ | 67108864 /* TypeFlags.Conditional */)) !== 0)
3512
+ constraint = getConstraintOfType(c, constraint);
3513
+ if (constraint !== undefined) {
3514
+ if (constraints === undefined)
3515
+ constraints = [];
3516
+ constraints.push(constraint);
3517
+ if (targetIsUnion)
3518
+ constraints.push(t);
3519
+ }
3520
+ }
3521
+ else if ((t.flags & 12812284 /* TypeFlags.DisjointDomains */) !== 0 || isEmptyAnonymousObjectType(c, t))
3522
+ hasDisjointDomainType = true;
3523
+ }
3524
+ if (constraints !== undefined && (targetIsUnion || hasDisjointDomainType)) {
3525
+ if (hasDisjointDomainType)
3526
+ for (const t of types)
3527
+ if ((t.flags & 12812284 /* TypeFlags.DisjointDomains */) !== 0 || isEmptyAnonymousObjectType(c, t))
3528
+ constraints.push(t);
3529
+ return getNormalizedType(c, getIntersectionTypeEx(c, constraints, 2 /* IntersectionFlags.NoConstraintReduction */, undefined), false);
3530
+ }
3531
+ return undefined;
3532
+ }
3533
+ function isSourceIntersectionNeedingExtraCheck(c, source, target) {
3534
+ return ((source.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
3535
+ (getApparentType(c, source).flags & 403701760 /* TypeFlags.StructuredType */) !== 0 &&
3536
+ !typesOf(source).some((t) => t === target || (t.objectFlags & 262144 /* ObjectFlags.NonInferrableType */) !== 0));
3537
+ }
3538
+ function isNonGenericObjectType(c, t) {
3539
+ return (t.flags & 1048576 /* TypeFlags.Object */) !== 0 && !isGenericMappedType(c, t);
3540
+ }
3541
+ function isSingleElementGenericTupleType(t) {
3542
+ return isGenericTupleType(t) && tupleTargetOf(t).elementInfos.length === 1;
3543
+ }
3544
+ function isMutableTupleType(t) {
3545
+ return isTupleType(t) && !tupleTargetOf(t).readonly;
3546
+ }
3547
+ function getConstraintFromTypeParameterChecked(c, t) {
3548
+ return getConstraintOfType(c, t);
3549
+ }
3550
+ function getKnownKeysOfTupleType(c, t) {
3551
+ const target = tupleTargetOf(t);
3552
+ const keys = [];
3553
+ for (let i = 0; i < target.fixedLength; i++)
3554
+ keys.push(getStringLiteralTypeLocal(c, String(i)));
3555
+ keys.push(getIndexType(c, target.readonly ? c.globalReadonlyArrayType : c.globalArrayType));
3556
+ return getUnionType(c, keys);
3557
+ }
3558
+ import { getStringLiteralType as getStringLiteralTypeLocal } from './checker-type-factory.js';
3559
+ function getSimplifiedTypeOrConstraint(c, t) {
3560
+ const simplified = getSimplifiedType(c, t, false);
3561
+ return simplified !== t ? simplified : getConstraintOfType(c, t);
3562
+ }
3563
+ function isDistributionDependent(c, t) {
3564
+ const root = t.root;
3565
+ const node = root.node;
3566
+ return (root.isDistributive &&
3567
+ (isTypeParameterPossiblyReferenced(c, root.checkType, node.trueType) ||
3568
+ isTypeParameterPossiblyReferenced(c, root.checkType, node.falseType)));
3569
+ }
3570
+ function templateLiteralTypesDefinitelyUnrelated(source, target) {
3571
+ const sourceStart = source.texts[0];
3572
+ const targetStart = target.texts[0];
3573
+ const sourceEnd = source.texts[source.texts.length - 1];
3574
+ const targetEnd = target.texts[target.texts.length - 1];
3575
+ return (!(sourceStart.length <= targetStart.length
3576
+ ? targetStart.startsWith(sourceStart)
3577
+ : sourceStart.startsWith(targetStart)) ||
3578
+ !(sourceEnd.length <= targetEnd.length ? targetEnd.endsWith(sourceEnd) : sourceEnd.endsWith(targetEnd)));
3579
+ }
3580
+ /**
3581
+ * Whether `source` starts and ends with the start and end texts of `target`, which a template literal
3582
+ * source needs to match `target` (see inferFromLiteralPartsToTemplateLiteral) or to be identical to it.
3583
+ */
3584
+ function templateLiteralTextsMayMatch(source, target) {
3585
+ return (source.texts[0].startsWith(target.texts[0]) &&
3586
+ source.texts[source.texts.length - 1].endsWith(target.texts[target.texts.length - 1]));
3587
+ }
3588
+ /**
3589
+ * Whether string literal `text` passes inferTypesFromTemplateLiteralType's start and end text test
3590
+ * against `target`, which it needs to match `target`.
3591
+ */
3592
+ function stringLiteralTextMayMatch(text, target) {
3593
+ const start = target.texts[0];
3594
+ const end = target.texts[target.texts.length - 1];
3595
+ return text.length >= start.length + end.length && text.startsWith(start) && text.endsWith(end);
3596
+ }
3597
+ function someTypeCouldContainTypeVariables(c, types) {
3598
+ for (const t of types)
3599
+ if (couldContainTypeVariables(c, t))
3600
+ return true;
3601
+ return false;
3602
+ }
3603
+ function isPartialMappedType(t) {
3604
+ return ((t.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 &&
3605
+ (t.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
3606
+ (getMappedTypeModifiers(t) & 4 /* MappedTypeModifiers.IncludeOptional */) !== 0);
3607
+ }
3608
+ export function isEmptyArrayLiteralType(c, t) {
3609
+ if (!isArrayType(c, t))
3610
+ return false;
3611
+ const elementType = getTypeArguments(c, t)[0];
3612
+ return c.strictNullChecks ? elementType === c.implicitNeverType : elementType === c.undefinedWideningType;
3613
+ }
3614
+ export function compareProperties(c, sourceProp, targetProp, compare) {
3615
+ return comparePropertiesWith(c, sourceProp, targetProp, getComparer(c, compare));
3616
+ }
3617
+ /** Public properties match on name, optionality and type; non-public ones must share a declaration. */
3618
+ function comparePropertiesWith(c, sourceProp, targetProp, comparer) {
3619
+ if (sourceProp === targetProp)
3620
+ return -1 /* Ternary.True */;
3621
+ const sourceAccessibility = getDeclarationModifierFlagsFromSymbol(c, sourceProp, false) & 6 /* ModifierFlags.NonPublicAccessibilityModifier */;
3622
+ const targetAccessibility = getDeclarationModifierFlagsFromSymbol(c, targetProp, false) & 6 /* ModifierFlags.NonPublicAccessibilityModifier */;
3623
+ if (sourceAccessibility !== targetAccessibility)
3624
+ return 0 /* Ternary.False */;
3625
+ if (sourceAccessibility !== 0) {
3626
+ if (getTargetSymbol(c, sourceProp) !== getTargetSymbol(c, targetProp))
3627
+ return 0 /* Ternary.False */;
3628
+ }
3629
+ else if ((sourceProp.flags & 16777216 /* SymbolFlags.Optional */) !== (targetProp.flags & 16777216 /* SymbolFlags.Optional */))
3630
+ return 0 /* Ternary.False */;
3631
+ if (isReadonlySymbol(c, sourceProp) !== isReadonlySymbol(c, targetProp))
3632
+ return 0 /* Ternary.False */;
3633
+ return comparer.compare(getNonMissingTypeOfSymbol(c, sourceProp), getNonMissingTypeOfSymbol(c, targetProp), false);
3634
+ }
3635
+ // ---- Signatures
3636
+ export function isSignatureAssignableTo(c, source, target, ignoreReturnTypes) {
3637
+ return (compareSignaturesRelated(c, source, target, ignoreReturnTypes ? 4 /* SignatureCheckMode.IgnoreReturnTypes */ : 0 /* SignatureCheckMode.None */, false, getComparer(c, 2 /* ComparerKind.Assignable */), undefined) !== 0 /* Ternary.False */);
3638
+ }
3639
+ export function compareSignaturesRelated(c, source, target, checkMode, reportErrors, comparer, reportUnreliableMarkers) {
3640
+ if (source === target)
3641
+ return -1 /* Ternary.True */;
3642
+ if (!((checkMode & 16 /* SignatureCheckMode.StrictTopSignature */) !== 0 && isTopSignature(c, source)) &&
3643
+ isTopSignature(c, target))
3644
+ return -1 /* Ternary.True */;
3645
+ if ((checkMode & 16 /* SignatureCheckMode.StrictTopSignature */) !== 0 &&
3646
+ isTopSignature(c, source) &&
3647
+ !isTopSignature(c, target))
3648
+ return 0 /* Ternary.False */;
3649
+ const targetCount = getParameterCount(c, target);
3650
+ const sourceHasMoreParameters = !hasEffectiveRestParameter(c, target) &&
3651
+ ((checkMode & 8 /* SignatureCheckMode.StrictArity */) !== 0
3652
+ ? hasEffectiveRestParameter(c, source) || getParameterCount(c, source) > targetCount
3653
+ : getMinArgumentCount(c, source) > targetCount);
3654
+ if (sourceHasMoreParameters) {
3655
+ if (reportErrors && (checkMode & 8 /* SignatureCheckMode.StrictArity */) === 0)
3656
+ comparer.report(969 /* Diagnostics.Target_signature_provides_too_few_arguments_Expected_0_or_more_but_got_1 */, [
3657
+ String(getMinArgumentCount(c, source)),
3658
+ String(targetCount),
3659
+ ]);
3660
+ return 0 /* Ternary.False */;
3661
+ }
3662
+ if (source.typeParameters.length !== 0 && source.typeParameters !== target.typeParameters) {
3663
+ target = getCanonicalSignature(c, target);
3664
+ source = instantiateSignatureInContextOf(c, source, target, comparer);
3665
+ }
3666
+ const sourceCount = getParameterCount(c, source);
3667
+ const sourceRestType = getNonArrayRestType(c, source);
3668
+ const targetRestType = getNonArrayRestType(c, target);
3669
+ if ((sourceRestType !== undefined || targetRestType !== undefined) && reportUnreliableMarkers !== undefined)
3670
+ instantiateType(c, sourceRestType ?? targetRestType, reportUnreliableMarkers);
3671
+ const kind = target.declaration !== undefined ? target.declaration.kind : 0 /* SyntaxKind.Unknown */;
3672
+ const strictVariance = (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 &&
3673
+ c.strictFunctionTypes &&
3674
+ kind !== 175 /* SyntaxKind.MethodDeclaration */ &&
3675
+ kind !== 174 /* SyntaxKind.MethodSignature */ &&
3676
+ kind !== 177 /* SyntaxKind.Constructor */;
3677
+ let result = -1 /* Ternary.True */;
3678
+ const sourceThisType = getThisTypeOfSignature(c, source);
3679
+ if (sourceThisType !== undefined && sourceThisType !== c.voidType) {
3680
+ const targetThisType = getThisTypeOfSignature(c, target);
3681
+ if (targetThisType !== undefined) {
3682
+ // void sources are assignable to anything.
3683
+ let related = !strictVariance ? comparer.compare(sourceThisType, targetThisType, false) : 0 /* Ternary.False */;
3684
+ if (related === 0 /* Ternary.False */)
3685
+ related = comparer.compare(targetThisType, sourceThisType, reportErrors);
3686
+ if (related === 0 /* Ternary.False */) {
3687
+ if (reportErrors)
3688
+ comparer.report(818 /* Diagnostics.The_this_types_of_each_signature_are_incompatible */, []);
3689
+ return 0 /* Ternary.False */;
3690
+ }
3691
+ result &= related;
3692
+ }
3693
+ }
3694
+ const hasRest = sourceRestType !== undefined || targetRestType !== undefined;
3695
+ const paramCount = hasRest ? Math.min(sourceCount, targetCount) : Math.max(sourceCount, targetCount);
3696
+ const restIndex = hasRest ? paramCount - 1 : -1;
3697
+ for (let i = 0; i < paramCount; i++) {
3698
+ const sourceType = i === restIndex ? getRestOrAnyTypeAtPosition(c, source, i) : tryGetTypeAtPosition(c, source, i);
3699
+ const targetType = i === restIndex ? getRestOrAnyTypeAtPosition(c, target, i) : tryGetTypeAtPosition(c, target, i);
3700
+ if (sourceType === undefined ||
3701
+ targetType === undefined ||
3702
+ (sourceType === targetType && (checkMode & 8 /* SignatureCheckMode.StrictArity */) === 0))
3703
+ continue;
3704
+ // Callback parameters relate covariantly; other parameters bivariantly unless strict.
3705
+ const sourceSig = (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 && !isInstantiatedGenericParameter(c, source, i)
3706
+ ? getSingleCallSignature(c, getNonNullableType(c, sourceType))
3707
+ : undefined;
3708
+ const targetSig = (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 && !isInstantiatedGenericParameter(c, target, i)
3709
+ ? getSingleCallSignature(c, getNonNullableType(c, targetType))
3710
+ : undefined;
3711
+ const callbacks = sourceSig !== undefined &&
3712
+ targetSig !== undefined &&
3713
+ getTypePredicateOfSignature(c, sourceSig) === undefined &&
3714
+ getTypePredicateOfSignature(c, targetSig) === undefined &&
3715
+ getTypeFacts(c, sourceType, 50331648 /* TypeFacts.IsUndefinedOrNull */) ===
3716
+ getTypeFacts(c, targetType, 50331648 /* TypeFacts.IsUndefinedOrNull */);
3717
+ let related;
3718
+ if (callbacks)
3719
+ related = compareSignaturesRelated(c, targetSig, sourceSig, (checkMode & 8 /* SignatureCheckMode.StrictArity */) |
3720
+ (strictVariance ? 2 /* SignatureCheckMode.StrictCallback */ : 1 /* SignatureCheckMode.BivariantCallback */), reportErrors, comparer, reportUnreliableMarkers);
3721
+ else {
3722
+ related =
3723
+ (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 && !strictVariance
3724
+ ? comparer.compare(sourceType, targetType, false)
3725
+ : 0 /* Ternary.False */;
3726
+ if (related === 0 /* Ternary.False */)
3727
+ related = comparer.compare(targetType, sourceType, reportErrors);
3728
+ }
3729
+ // With strict arity, `(x: number | undefined) => void` is a subtype of `(x?: number | undefined) => void`.
3730
+ if (related !== 0 /* Ternary.False */ &&
3731
+ (checkMode & 8 /* SignatureCheckMode.StrictArity */) !== 0 &&
3732
+ i >= getMinArgumentCount(c, source) &&
3733
+ i < getMinArgumentCount(c, target) &&
3734
+ comparer.compare(sourceType, targetType, false) !== 0 /* Ternary.False */)
3735
+ related = 0 /* Ternary.False */;
3736
+ if (related === 0 /* Ternary.False */) {
3737
+ if (reportErrors)
3738
+ comparer.report(506 /* Diagnostics.Types_of_parameters_0_and_1_are_incompatible */, [
3739
+ getParameterNameAtPosition(c, source, i),
3740
+ getParameterNameAtPosition(c, target, i),
3741
+ ]);
3742
+ return 0 /* Ternary.False */;
3743
+ }
3744
+ result &= related;
3745
+ }
3746
+ if ((checkMode & 4 /* SignatureCheckMode.IgnoreReturnTypes */) === 0) {
3747
+ // In-flight return type resolutions use `any`.
3748
+ const targetReturnType = getNonCircularReturnTypeOfSignature(c, target);
3749
+ if (targetReturnType === c.voidType || targetReturnType === c.anyType)
3750
+ return result;
3751
+ const sourceReturnType = getNonCircularReturnTypeOfSignature(c, source);
3752
+ const targetTypePredicate = getTypePredicateOfSignature(c, target);
3753
+ if (targetTypePredicate !== undefined) {
3754
+ const sourceTypePredicate = getTypePredicateOfSignature(c, source);
3755
+ if (sourceTypePredicate !== undefined)
3756
+ result &= compareTypePredicateRelatedTo(c, sourceTypePredicate, targetTypePredicate, reportErrors, comparer);
3757
+ else if (targetTypePredicate.kind === 1 /* TypePredicateKind.Identifier */ ||
3758
+ targetTypePredicate.kind === 0 /* TypePredicateKind.This */) {
3759
+ if (reportErrors)
3760
+ comparer.report(174 /* Diagnostics.Signature_0_must_be_a_type_predicate */, [signatureToString(c, source)]);
3761
+ return 0 /* Ternary.False */;
3762
+ }
3763
+ }
3764
+ else {
3765
+ // Callback return types relate bivariantly to keep containing types covariant.
3766
+ let related = (checkMode & 1 /* SignatureCheckMode.BivariantCallback */) !== 0
3767
+ ? comparer.compare(targetReturnType, sourceReturnType, false)
3768
+ : 0 /* Ternary.False */;
3769
+ if (related === 0 /* Ternary.False */)
3770
+ related = comparer.compare(sourceReturnType, targetReturnType, reportErrors);
3771
+ result &= related;
3772
+ if (result === 0 /* Ternary.False */ && reportErrors) {
3773
+ // Markers for chain reduction in reportError; elided from output.
3774
+ const construct = (source.flags & 4 /* SignatureFlags.Construct */) !== 0;
3775
+ const message = source.parameters.length === 0 && target.parameters.length === 0
3776
+ ? construct
3777
+ ? 470 /* Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */
3778
+ : 469 /* Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */
3779
+ : construct
3780
+ ? 468 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */
3781
+ : 467 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */;
3782
+ comparer.report(message, [typeToString(c, sourceReturnType), typeToString(c, targetReturnType)]);
3783
+ }
3784
+ }
3785
+ }
3786
+ return result;
3787
+ }
3788
+ function isInstantiatedGenericParameter(c, signature, pos) {
3789
+ if (signature.target === undefined)
3790
+ return false;
3791
+ const t = tryGetTypeAtPosition(c, signature.target, pos);
3792
+ return t !== undefined && isGenericTypeLocal(c, t);
3793
+ }
3794
+ function compareTypePredicateRelatedTo(c, source, target, reportErrors, comparer) {
3795
+ if (source.kind !== target.kind) {
3796
+ if (reportErrors) {
3797
+ comparer.report(678 /* Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard */, []);
3798
+ comparer.report(176 /* Diagnostics.Type_predicate_0_is_not_assignable_to_1 */, [
3799
+ typePredicateToString(c, source),
3800
+ typePredicateToString(c, target),
3801
+ ]);
3802
+ }
3803
+ return 0 /* Ternary.False */;
3804
+ }
3805
+ if ((source.kind === 1 /* TypePredicateKind.Identifier */ || source.kind === 3 /* TypePredicateKind.AssertsIdentifier */) &&
3806
+ source.parameterIndex !== target.parameterIndex) {
3807
+ if (reportErrors) {
3808
+ comparer.report(177 /* Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1 */, [
3809
+ source.parameterName,
3810
+ target.parameterName,
3811
+ ]);
3812
+ comparer.report(176 /* Diagnostics.Type_predicate_0_is_not_assignable_to_1 */, [
3813
+ typePredicateToString(c, source),
3814
+ typePredicateToString(c, target),
3815
+ ]);
3816
+ }
3817
+ return 0 /* Ternary.False */;
3818
+ }
3819
+ let related;
3820
+ if (source.type === target.type)
3821
+ related = -1 /* Ternary.True */;
3822
+ else if (source.type !== undefined && target.type !== undefined)
3823
+ related = comparer.compare(source.type, target.type, reportErrors);
3824
+ else
3825
+ related = 0 /* Ternary.False */;
3826
+ if (related === 0 /* Ternary.False */ && reportErrors)
3827
+ comparer.report(176 /* Diagnostics.Type_predicate_0_is_not_assignable_to_1 */, [
3828
+ typePredicateToString(c, source),
3829
+ typePredicateToString(c, target),
3830
+ ]);
3831
+ return related;
3832
+ }
3833
+ export function compareSignaturesIdentical(c, source, target, partialMatch, ignoreThisTypes, ignoreReturnTypes, compare) {
3834
+ return compareSignaturesIdenticalWith(c, source, target, partialMatch, ignoreThisTypes, ignoreReturnTypes, getComparer(c, compare));
3835
+ }
3836
+ function compareSignaturesIdenticalWith(c, source, target, partialMatch, ignoreThisTypes, ignoreReturnTypes, comparer) {
3837
+ if (source === target)
3838
+ return -1 /* Ternary.True */;
3839
+ if (!isMatchingSignature(c, source, target, partialMatch))
3840
+ return 0 /* Ternary.False */;
3841
+ if (source.typeParameters.length !== target.typeParameters.length)
3842
+ return 0 /* Ternary.False */;
3843
+ // Matching constraints and defaults let us instantiate the source with the target's type parameters.
3844
+ if (target.typeParameters.length !== 0) {
3845
+ const mapper = newTypeMapper(source.typeParameters, target.typeParameters);
3846
+ for (let i = 0; i < target.typeParameters.length; i++) {
3847
+ const s = source.typeParameters[i];
3848
+ const t = target.typeParameters[i];
3849
+ if (s === t)
3850
+ continue;
3851
+ if (comparer.compare(instantiateType(c, getConstraintFromTypeParameter(c, s) ?? c.unknownType, mapper), getConstraintFromTypeParameter(c, t) ?? c.unknownType, false) === 0 /* Ternary.False */ ||
3852
+ comparer.compare(instantiateType(c, getDefaultOrUnknownFromTypeParameter(c, s), mapper), getDefaultOrUnknownFromTypeParameter(c, t), false) === 0 /* Ternary.False */)
3853
+ return 0 /* Ternary.False */;
3854
+ }
3855
+ source = instantiateSignatureEx(c, source, mapper, true);
3856
+ }
3857
+ let result = -1 /* Ternary.True */;
3858
+ if (!ignoreThisTypes) {
3859
+ const sourceThisType = getThisTypeOfSignature(c, source);
3860
+ if (sourceThisType !== undefined) {
3861
+ const targetThisType = getThisTypeOfSignature(c, target);
3862
+ if (targetThisType !== undefined) {
3863
+ const related = comparer.compare(sourceThisType, targetThisType, false);
3864
+ if (related === 0 /* Ternary.False */)
3865
+ return 0 /* Ternary.False */;
3866
+ result &= related;
3867
+ }
3868
+ }
3869
+ }
3870
+ const count = getParameterCount(c, target);
3871
+ for (let i = 0; i < count; i++) {
3872
+ const related = comparer.compare(getTypeAtPosition(c, target, i), getTypeAtPosition(c, source, i), false);
3873
+ if (related === 0 /* Ternary.False */)
3874
+ return 0 /* Ternary.False */;
3875
+ result &= related;
3876
+ }
3877
+ if (!ignoreReturnTypes) {
3878
+ const sourceTypePredicate = getTypePredicateOfSignature(c, source);
3879
+ const targetTypePredicate = getTypePredicateOfSignature(c, target);
3880
+ if (sourceTypePredicate !== undefined || targetTypePredicate !== undefined) {
3881
+ if (sourceTypePredicate === undefined ||
3882
+ targetTypePredicate === undefined ||
3883
+ sourceTypePredicate.kind !== targetTypePredicate.kind ||
3884
+ sourceTypePredicate.parameterIndex !== targetTypePredicate.parameterIndex)
3885
+ return 0 /* Ternary.False */;
3886
+ if (sourceTypePredicate.type !== targetTypePredicate.type) {
3887
+ if (sourceTypePredicate.type === undefined || targetTypePredicate.type === undefined)
3888
+ return 0 /* Ternary.False */;
3889
+ result &= comparer.compare(sourceTypePredicate.type, targetTypePredicate.type, false);
3890
+ }
3891
+ }
3892
+ else
3893
+ result &= comparer.compare(getReturnTypeOfSignature(c, source), getReturnTypeOfSignature(c, target), false);
3894
+ }
3895
+ return result;
3896
+ }
3897
+ function isMatchingSignature(c, source, target, partialMatch) {
3898
+ const sourceParameterCount = getParameterCount(c, source);
3899
+ const targetParameterCount = getParameterCount(c, target);
3900
+ const sourceMinArgumentCount = getMinArgumentCount(c, source);
3901
+ const targetMinArgumentCount = getMinArgumentCount(c, target);
3902
+ if (sourceParameterCount === targetParameterCount &&
3903
+ sourceMinArgumentCount === targetMinArgumentCount &&
3904
+ hasEffectiveRestParameter(c, source) === hasEffectiveRestParameter(c, target))
3905
+ return true;
3906
+ return partialMatch && sourceMinArgumentCount <= targetMinArgumentCount;
3907
+ }
3908
+ /**
3909
+ * Whether `source` derives from `target` in the inheritance hierarchy, ignoring type parameters;
3910
+ * `{}`, Object and Function are less derived than object-like types.
3911
+ */
3912
+ export function isTypeDerivedFrom(c, source, target) {
3913
+ if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0) {
3914
+ for (const t of typesOf(source))
3915
+ if (!isTypeDerivedFrom(c, t, target))
3916
+ return false;
3917
+ return true;
3918
+ }
3919
+ if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
3920
+ for (const t of typesOf(target))
3921
+ if (isTypeDerivedFrom(c, source, t))
3922
+ return true;
3923
+ return false;
3924
+ }
3925
+ if ((source.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
3926
+ for (const t of typesOf(source))
3927
+ if (isTypeDerivedFrom(c, t, target))
3928
+ return true;
3929
+ return false;
3930
+ }
3931
+ if ((source.flags & 117964800 /* TypeFlags.InstantiableNonPrimitive */) !== 0)
3932
+ return isTypeDerivedFrom(c, getBaseConstraintOfType(c, source) ?? c.unknownType, target);
3933
+ if (isEmptyAnonymousObjectType(c, target))
3934
+ return (source.flags & (1048576 /* TypeFlags.Object */ | 131072 /* TypeFlags.NonPrimitive */)) !== 0;
3935
+ if (target === c.globalObjectType)
3936
+ return (source.flags & (1048576 /* TypeFlags.Object */ | 131072 /* TypeFlags.NonPrimitive */)) !== 0 && !isEmptyAnonymousObjectType(c, source);
3937
+ if (target === c.globalFunctionType)
3938
+ return (source.flags & 1048576 /* TypeFlags.Object */) !== 0 && isFunctionObjectType(c, source);
3939
+ return (hasBaseType(c, source, getTargetType(target)) ||
3940
+ (isArrayType(c, target) &&
3941
+ !isReadonlyArrayType(c, target) &&
3942
+ isTypeDerivedFrom(c, source, c.globalReadonlyArrayType)));
3943
+ }
3944
+ function isFunctionObjectType(c, t) {
3945
+ if ((t.objectFlags & 256 /* ObjectFlags.EvolvingArray */) !== 0)
3946
+ return false;
3947
+ const resolved = resolveStructuredTypeMembers(c, t);
3948
+ return (resolved.callSignatures.length !== 0 ||
3949
+ resolved.constructSignatures.length !== 0 ||
3950
+ (getResolvedMember(resolved, 'bind') !== undefined && isTypeSubtypeOf(c, t, c.globalFunctionType)));
3951
+ }
3952
+ export { findApplicableIndexInfo, getMergedSymbol, typeListKey, getPropertyNameFromType };
3953
+ /** The target properties that accept `undefined` only through `?`, under exactOptionalPropertyTypes. */
3954
+ export function getExactOptionalUnassignableProperties(c, source, target) {
3955
+ if (isTupleType(source) && isTupleType(target))
3956
+ return [];
3957
+ const result = [];
3958
+ for (const targetProp of getPropertiesOfType(c, target))
3959
+ if (isExactOptionalPropertyMismatch(c, getTypeOfPropertyOfType(c, source, targetProp.name), getTypeOfSymbol(c, targetProp)))
3960
+ result.push(targetProp);
3961
+ return result;
3962
+ }
3963
+ /**
3964
+ * Whether `source` may be `undefined` where the optional property type `target` takes it only by being
3965
+ * missing, under exactOptionalPropertyTypes.
3966
+ */
3967
+ export function isExactOptionalPropertyMismatch(c, source, target) {
3968
+ return (source !== undefined &&
3969
+ target !== undefined &&
3970
+ maybeTypeOfKind(source, 4 /* TypeFlags.Undefined */) &&
3971
+ containsMissingType(c, target));
3972
+ }
3973
+ /** The string literal member of `target` closest to the string literal `source`. */
3974
+ function getSuggestedTypeForNonexistentStringLiteralType(c, source, target) {
3975
+ const value = source.stringValue;
3976
+ const valueCodePoints = new CodePoints();
3977
+ valueCodePoints.set(value);
3978
+ const maximumLengthDifference = Math.max(2, Math.floor(valueCodePoints.length * 0.34));
3979
+ let bestDistance = Math.floor(valueCodePoints.length * 0.4) + 0.9;
3980
+ let best = undefined;
3981
+ const lowerValue = value.toLowerCase();
3982
+ for (const t of typesOf(target)) {
3983
+ if ((t.flags & 1024 /* TypeFlags.StringLiteral */) === 0)
3984
+ continue;
3985
+ const name = t.stringValue;
3986
+ const nameLength = utf8Length(name);
3987
+ if (name === '' || Math.abs(nameLength - valueCodePoints.length) > maximumLengthDifference || name === value)
3988
+ continue;
3989
+ if (nameLength < 3 && name.toLowerCase() !== lowerValue)
3990
+ continue;
3991
+ const distance = distanceToCandidate(valueCodePoints, name, bestDistance);
3992
+ if (distance < 0)
3993
+ continue;
3994
+ if (distance < bestDistance) {
3995
+ bestDistance = distance;
3996
+ best = t;
3997
+ }
3998
+ else if (best === undefined || compareTypes(c, t, best) < 0)
3999
+ best = t;
4000
+ }
4001
+ return best;
4002
+ }