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.
- package/README.md +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,1640 @@
|
|
|
1
|
+
// Calls, `new` and tagged templates: signature resolution with type argument inference and overload
|
|
2
|
+
// selection, argument checks and resolution errors.
|
|
3
|
+
import { checkDeprecatedSignature } from './checker-deprecation.js';
|
|
4
|
+
import { Node, getArguments as getArgumentList, getExpression, getName, getParameters, getText, getTypeArguments as getTypeArgumentList, getNodeId, getBody, getSymbol, } from './ast.js';
|
|
5
|
+
import { canHaveDecorators, getEffectiveCheckNode, isFunctionLikeDeclarationKind, isImportCall, nodeIsPresent, } from './ast-utilities.js';
|
|
6
|
+
import { getContainingClass, getSourceFileOfNode, isAccessExpression, isExpressionOfOptionalChainRoot, isOptionalChain, isOutermostOptionalChain, isDottedName, } from './binder-utilities.js';
|
|
7
|
+
import { Diagnostic, chainDiagnostic } from './diagnostics.js';
|
|
8
|
+
import { resolveInstanceofExpression } from './checker-operators.js';
|
|
9
|
+
import { skipTrivia } from './scanner.js';
|
|
10
|
+
import { createDiagnosticForNode } from './checker.js';
|
|
11
|
+
import { checkSuperExpression } from './checker-super.js';
|
|
12
|
+
import { isConstructorAccessible } from './checker-classes.js';
|
|
13
|
+
import { getDecoratorArgumentCount, getDecoratorCallSignature, getDiagnosticHeadMessageForDecoratorResolution, getEffectiveDecoratorArgumentTypes, getUncalledDecoratorText, isPotentiallyUncalledDecorator, } from './checker-decorators.js';
|
|
14
|
+
import { TupleElementInfo, newTypeMapper, } from './checker-types.js';
|
|
15
|
+
import { getGlobalTemplateStringsArrayType } from './checker-globals.js';
|
|
16
|
+
import { createArrayType, createArrayTypeEx, createTupleTypeEx, filterType, getElementTypes, getIntersectionType, getNumberLiteralType, getRegularTypeOfLiteralType, getUnionTypeEx, getWidenedLiteralType, isErrorType, isMutableArrayOrTuple, isTupleType, mapType, newObjectType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
17
|
+
import { createSymbolWithType, getApparentType, getBaseConstraintOfType, resolveStructuredTypeMembers, getBaseConstraintOrType, getIndexTypeOfType, getReducedType, getSignaturesOfType, getTypeWithThisArgument, isArrayLikeType, } from './checker-members.js';
|
|
18
|
+
import { createSignatureInstantiation, getMinArgumentCount, getNonArrayRestType, getOrCreateTypeFromSignature, getParameterCount, getReturnTypeOfSignature, getSignatureInstantiation, getSignatureInstantiationWithoutFillingInTypeArguments, getSingleCallOrConstructSignature, getSingleCallSignature, getSingleSignature, getThisTypeOfSignature, getTypeAtPosition, getTypeOfParameter, hasEffectiveRestParameter, cloneSignature, tryGetTypeAtPosition, getTypePredicateOfSignature, getSignatureFromDeclaration, } from './checker-signatures.js';
|
|
19
|
+
import { getEffectsSignature } from './checker-narrowing.js';
|
|
20
|
+
import { addOptionalTypeMarker, getOptionalType, getTypeOfSymbol, removeOptionalTypeMarker, } from './checker-symbol-types.js';
|
|
21
|
+
import { checkTypeRelatedTo, getRegularTypeOfObjectLiteral, isTypeAssignableTo } from './relations.js';
|
|
22
|
+
import { getNonNullableType } from './checker-flow.js';
|
|
23
|
+
import { checkExpression, checkExpressionCached, checkNonNullType, checkNonNullTypeEx, checkTypeQueryExpression, } from './checker-expressions.js';
|
|
24
|
+
import { checkIteratedTypeOrElementType } from './checker-iteration.js';
|
|
25
|
+
import { isContextSensitive } from './checker-functions.js';
|
|
26
|
+
import { getExtendsHeritageClauseElement, getInstantiatedConstructorsForTypeArguments, fillMissingTypeArguments, getConstraintOfTypeParameter, getDefaultFromTypeParameter, getMinTypeArgumentCount, } from './checker-declared-types.js';
|
|
27
|
+
import { getESSymbolLikeTypeForNode, getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
28
|
+
import { getIndexedAccessTypeEx, getRestTypeOfTupleType } from './checker-type-operators.js';
|
|
29
|
+
import { instantiateType, isNodeDescendantOf } from './instantiation.js';
|
|
30
|
+
import { maybeTypeOfKind } from './checker-utilities.js';
|
|
31
|
+
import { checkSourceElement, checkNodeDeferred } from './checker-source-file.js';
|
|
32
|
+
import { InferenceInfo, applyToParameterTypes, applyToReturnTypes, hasOverlappingInferences, instantiateSignatureInContextOf, mergeInferences, cloneInferenceContext, cloneInferredPartOfContext, createInferenceContext, createOuterReturnMapper, getInferredTypes, getMapperFromContext, everyInferenceHasCandidates, someInferenceHasCandidates, inferTypes, isConstTypeVariable, isMutableArrayLikeType, } from './checker-inference.js';
|
|
33
|
+
import { checkExpressionWithContextualType, getApparentTypeOfContextualTypeEx, getContextualTypeEx, getContextualTypeForElementExpression, getInferenceContext, } from './checker-contextual.js';
|
|
34
|
+
import { couldContainTypeVariables } from './instantiation.js';
|
|
35
|
+
import { typeToString } from './type-printer.js';
|
|
36
|
+
import { checkTypeRelatedToAndOptionallyElaborate } from './checker-elaboration.js';
|
|
37
|
+
import { getGlobalValueSymbol, getSymbolOfDeclaration, resolveName } from './checker-symbols.js';
|
|
38
|
+
import { checkImportCallExpression } from './checker-modules.js';
|
|
39
|
+
import { checkApplicableSignatureForJsxCallLikeElement, getAttributesOf, getEffectiveJsxArguments, inferJsxTypeArguments, isJsxOpeningLikeElement, resolveJsxOpeningLikeElement, } from './checker-jsx.js';
|
|
40
|
+
import { isCommonJSRequire, resolveExternalModuleTypeByLiteral } from './checker-javascript.js';
|
|
41
|
+
/** The type of an optional chain's expression with the chain's `undefined` removed. */
|
|
42
|
+
export function getOptionalExpressionType(c, exprType, expression) {
|
|
43
|
+
if (isExpressionOfOptionalChainRoot(expression))
|
|
44
|
+
return getNonNullableType(c, exprType);
|
|
45
|
+
if (isOptionalChain(expression))
|
|
46
|
+
return removeOptionalTypeMarker(c, exprType);
|
|
47
|
+
return exprType;
|
|
48
|
+
}
|
|
49
|
+
export function propagateOptionalTypeMarker(c, t, node, wasOptional) {
|
|
50
|
+
if (!wasOptional)
|
|
51
|
+
return t;
|
|
52
|
+
return isOutermostOptionalChain(node) ? getOptionalType(c, t, false) : addOptionalTypeMarker(c, t);
|
|
53
|
+
}
|
|
54
|
+
// ---- Entry points
|
|
55
|
+
export function checkCallExpression(c, node, checkMode) {
|
|
56
|
+
const call = node;
|
|
57
|
+
const callee = call.expression;
|
|
58
|
+
if (isImportCall(node))
|
|
59
|
+
return checkImportCallExpression(c, node);
|
|
60
|
+
const signature = getResolvedSignature(c, node, checkMode);
|
|
61
|
+
// A deferred call to a generic function returning a function, under SkipGenericFunctions.
|
|
62
|
+
if (signature === c.resolvingSignature)
|
|
63
|
+
return c.silentNeverType;
|
|
64
|
+
checkDeprecatedSignature(c, signature, node);
|
|
65
|
+
if (callee.kind === 107 /* SyntaxKind.SuperKeyword */)
|
|
66
|
+
return c.voidType;
|
|
67
|
+
if (isInJSFile(node) && isCommonJSRequire(c, node))
|
|
68
|
+
return resolveExternalModuleTypeByLiteral(c, call.arguments.nodes[0]);
|
|
69
|
+
const returnType = getReturnTypeOfSignature(c, signature);
|
|
70
|
+
// A call of the global `Symbol` in a const or readonly declaration is a fresh unique symbol.
|
|
71
|
+
if ((returnType.flags & 16896 /* TypeFlags.ESSymbolLike */) !== 0 && isSymbolOrSymbolForCall(c, call))
|
|
72
|
+
return getESSymbolLikeTypeForNode(c, walkUpParenthesizedExpressions(node.parent));
|
|
73
|
+
// An assertion call must name its target through explicitly typed declarations.
|
|
74
|
+
if (call.questionDotToken === undefined &&
|
|
75
|
+
node.parent.kind === 245 /* SyntaxKind.ExpressionStatement */ &&
|
|
76
|
+
(returnType.flags & 16 /* TypeFlags.Void */) !== 0 &&
|
|
77
|
+
getTypePredicateOfSignature(c, signature) !== undefined) {
|
|
78
|
+
if (!isDottedName(callee))
|
|
79
|
+
c.error(callee, 908 /* Diagnostics.Assertions_require_the_call_target_to_be_an_identifier_or_qualified_name */);
|
|
80
|
+
else if (getEffectsSignature(c, node) === undefined)
|
|
81
|
+
c.error(callee, 907 /* Diagnostics.Assertions_require_every_name_in_the_call_target_to_be_declared_with_an_explicit_type_annotation */);
|
|
82
|
+
}
|
|
83
|
+
return returnType;
|
|
84
|
+
}
|
|
85
|
+
function walkUpParenthesizedExpressions(node) {
|
|
86
|
+
let current = node;
|
|
87
|
+
while (current.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
|
|
88
|
+
current = current.parent;
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
/** Whether `node` calls the global `Symbol` or `Symbol.for`. */
|
|
92
|
+
export function isSymbolOrSymbolForCall(c, node) {
|
|
93
|
+
let left = node.expression;
|
|
94
|
+
if (left.kind === 212 /* SyntaxKind.PropertyAccessExpression */ && getText(getName(left)) === 'for')
|
|
95
|
+
left = getExpression(left);
|
|
96
|
+
if (left.kind !== 79 /* SyntaxKind.Identifier */ || getText(left) !== 'Symbol')
|
|
97
|
+
return false;
|
|
98
|
+
const globalESSymbol = getGlobalValueSymbol(c, 'Symbol', false);
|
|
99
|
+
return (globalESSymbol !== undefined &&
|
|
100
|
+
globalESSymbol === resolveName(c, left, 'Symbol', 111551 /* SymbolFlags.Value */, undefined, false, false));
|
|
101
|
+
}
|
|
102
|
+
export function checkNewExpression(c, node, checkMode) {
|
|
103
|
+
const signature = getResolvedSignature(c, node, checkMode);
|
|
104
|
+
if (signature === c.resolvingSignature)
|
|
105
|
+
return c.silentNeverType;
|
|
106
|
+
checkDeprecatedSignature(c, signature, node);
|
|
107
|
+
const declaration = signature.declaration;
|
|
108
|
+
if (declaration !== undefined &&
|
|
109
|
+
declaration.kind !== 177 /* SyntaxKind.Constructor */ &&
|
|
110
|
+
declaration.kind !== 181 /* SyntaxKind.ConstructSignature */ &&
|
|
111
|
+
declaration.kind !== 186 /* SyntaxKind.ConstructorType */) {
|
|
112
|
+
// A call signature resolved for `new` makes the result `any`.
|
|
113
|
+
if (c.noImplicitAny)
|
|
114
|
+
c.error(node, 1681 /* Diagnostics.X_new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type */);
|
|
115
|
+
return c.anyType;
|
|
116
|
+
}
|
|
117
|
+
return getReturnTypeOfSignature(c, signature);
|
|
118
|
+
}
|
|
119
|
+
export function checkTaggedTemplateExpression(c, node, checkMode) {
|
|
120
|
+
const signature = getResolvedSignature(c, node, checkMode);
|
|
121
|
+
if (signature === c.resolvingSignature)
|
|
122
|
+
return c.silentNeverType;
|
|
123
|
+
checkDeprecatedSignature(c, signature, node);
|
|
124
|
+
return getReturnTypeOfSignature(c, signature);
|
|
125
|
+
}
|
|
126
|
+
/** The signature `node` resolves to, computed once. */
|
|
127
|
+
export function getResolvedSignature(c, node, checkMode) {
|
|
128
|
+
const cached = c.resolvedSignatures.get(node.id);
|
|
129
|
+
if (cached !== undefined && cached !== c.resolvingSignature)
|
|
130
|
+
return cached;
|
|
131
|
+
const saveResolutionStart = c.resolutionStart;
|
|
132
|
+
// Reset the resolution stack so inverted requests retry with the resolving marker in place.
|
|
133
|
+
if (cached === undefined)
|
|
134
|
+
c.resolutionStart = c.resolutionDepth;
|
|
135
|
+
c.resolvedSignatures.set(node.id, c.resolvingSignature);
|
|
136
|
+
let result = resolveSignature(c, node, checkMode);
|
|
137
|
+
c.resolutionStart = saveResolutionStart;
|
|
138
|
+
// resolvingSignature means resolution was deferred under SkipGenericFunctions.
|
|
139
|
+
if (result !== c.resolvingSignature) {
|
|
140
|
+
// A nested resolution may have cached the source-order result first; prefer it.
|
|
141
|
+
if (c.resolvedSignatures.get(node.id) !== c.resolvingSignature)
|
|
142
|
+
result = c.resolvedSignatures.get(node.id);
|
|
143
|
+
// Results computed during loop analysis may rest on transient flow types.
|
|
144
|
+
c.resolvedSignatures.set(node.id, c.flowLoopStack.length === 0 ? result : cached);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
/** The signature argument contextual types come from while `call` is checked. */
|
|
149
|
+
export function resolveCallSignatureForContext(c, call) {
|
|
150
|
+
return c.resolvedSignatures.get(call.id) === c.resolvingSignature
|
|
151
|
+
? c.resolvingSignature
|
|
152
|
+
: getResolvedSignature(c, call, 0 /* CheckMode.Normal */);
|
|
153
|
+
}
|
|
154
|
+
function resolveSignature(c, node, checkMode) {
|
|
155
|
+
switch (node.kind) {
|
|
156
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
157
|
+
return resolveCallExpression(c, node, checkMode);
|
|
158
|
+
case 215 /* SyntaxKind.NewExpression */:
|
|
159
|
+
return resolveNewExpression(c, node, checkMode);
|
|
160
|
+
case 216 /* SyntaxKind.TaggedTemplateExpression */:
|
|
161
|
+
return resolveTaggedTemplateExpression(c, node, checkMode);
|
|
162
|
+
case 287 /* SyntaxKind.JsxOpeningElement */:
|
|
163
|
+
case 286 /* SyntaxKind.JsxSelfClosingElement */:
|
|
164
|
+
case 290 /* SyntaxKind.JsxOpeningFragment */:
|
|
165
|
+
return resolveJsxOpeningLikeElement(c, node, checkMode);
|
|
166
|
+
case 171 /* SyntaxKind.Decorator */:
|
|
167
|
+
return resolveDecorator(c, node, checkMode);
|
|
168
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
169
|
+
return resolveInstanceofExpression(c, node, checkMode);
|
|
170
|
+
}
|
|
171
|
+
return resolveUntypedCall(c, node);
|
|
172
|
+
}
|
|
173
|
+
function resolveCallExpression(c, node, checkMode) {
|
|
174
|
+
const callee = node.expression;
|
|
175
|
+
if (callee.kind === 107 /* SyntaxKind.SuperKeyword */)
|
|
176
|
+
return resolveSuperCall(c, node, checkMode);
|
|
177
|
+
let callChainFlags = 0 /* SignatureFlags.None */;
|
|
178
|
+
let funcType = checkExpression(c, callee);
|
|
179
|
+
if (isOptionalChain(node)) {
|
|
180
|
+
const nonOptionalType = getOptionalExpressionType(c, funcType, callee);
|
|
181
|
+
callChainFlags =
|
|
182
|
+
nonOptionalType === funcType
|
|
183
|
+
? 0 /* SignatureFlags.None */
|
|
184
|
+
: isOutermostOptionalChain(node)
|
|
185
|
+
? 32 /* SignatureFlags.IsOuterCallChain */
|
|
186
|
+
: 16 /* SignatureFlags.IsInnerCallChain */;
|
|
187
|
+
funcType = nonOptionalType;
|
|
188
|
+
}
|
|
189
|
+
funcType = checkNonNullTypeForCall(c, funcType, callee);
|
|
190
|
+
if (funcType === c.silentNeverType)
|
|
191
|
+
return c.silentNeverSignature;
|
|
192
|
+
const apparentType = getApparentType(c, funcType);
|
|
193
|
+
if (isErrorType(c, apparentType))
|
|
194
|
+
return resolveErrorCall(c, node);
|
|
195
|
+
const callSignatures = getSignaturesOfType(c, apparentType, 0 /* SignatureKind.Call */);
|
|
196
|
+
const numConstructSignatures = getSignaturesOfType(c, apparentType, 1 /* SignatureKind.Construct */).length;
|
|
197
|
+
if (isUntypedFunctionCall(c, funcType, apparentType, callSignatures.length, numConstructSignatures)) {
|
|
198
|
+
if (!isErrorType(c, funcType) && node.typeArguments !== undefined)
|
|
199
|
+
c.error(node, 523 /* Diagnostics.Untyped_function_calls_may_not_accept_type_arguments */);
|
|
200
|
+
return resolveUntypedCall(c, node);
|
|
201
|
+
}
|
|
202
|
+
if (callSignatures.length === 0) {
|
|
203
|
+
if (numConstructSignatures !== 0)
|
|
204
|
+
c.error(node, 524 /* Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new */, typeToString(c, funcType));
|
|
205
|
+
else
|
|
206
|
+
invocationError(c, callee, apparentType, 0 /* SignatureKind.Call */);
|
|
207
|
+
return resolveErrorCall(c, node);
|
|
208
|
+
}
|
|
209
|
+
// An inner generic call returning a function is deferred while an outer call infers, so that
|
|
210
|
+
// inferences can flow through function composition.
|
|
211
|
+
if ((checkMode & 8 /* CheckMode.SkipGenericFunctions */) !== 0 &&
|
|
212
|
+
node.typeArguments === undefined &&
|
|
213
|
+
someGenericFunctionReturningFunction(c, callSignatures)) {
|
|
214
|
+
skippedGenericFunction(c, node, checkMode);
|
|
215
|
+
return c.resolvingSignature;
|
|
216
|
+
}
|
|
217
|
+
return resolveCall(c, node, callSignatures, checkMode, callChainFlags, undefined);
|
|
218
|
+
}
|
|
219
|
+
/** A `super(...)` call resolves against the base constructors instantiated with the `extends` type arguments. */
|
|
220
|
+
function resolveSuperCall(c, node, checkMode) {
|
|
221
|
+
const superType = checkSuperExpression(c, node.expression);
|
|
222
|
+
if ((superType.flags & 1 /* TypeFlags.Any */) !== 0) {
|
|
223
|
+
// Arguments are still checked.
|
|
224
|
+
for (const arg of node.arguments.nodes)
|
|
225
|
+
checkExpression(c, arg);
|
|
226
|
+
return c.anySignature;
|
|
227
|
+
}
|
|
228
|
+
if (!isErrorType(c, superType)) {
|
|
229
|
+
const classDeclaration = getContainingClass(node);
|
|
230
|
+
const baseTypeNode = classDeclaration !== undefined ? getExtendsHeritageClauseElement(classDeclaration) : undefined;
|
|
231
|
+
if (baseTypeNode !== undefined) {
|
|
232
|
+
const typeArguments = getTypeArgumentList(baseTypeNode);
|
|
233
|
+
const baseConstructors = getInstantiatedConstructorsForTypeArguments(c, superType, typeArguments !== undefined ? typeArguments.nodes : undefined, baseTypeNode);
|
|
234
|
+
return resolveCall(c, node, baseConstructors, checkMode, 0 /* SignatureFlags.None */, undefined);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return resolveUntypedCall(c, node);
|
|
238
|
+
}
|
|
239
|
+
function resolveNewExpression(c, node, checkMode) {
|
|
240
|
+
let expressionType = checkNonNullType(c, checkExpression(c, node.expression), node.expression);
|
|
241
|
+
if (expressionType === c.silentNeverType)
|
|
242
|
+
return c.silentNeverSignature;
|
|
243
|
+
expressionType = getApparentType(c, expressionType);
|
|
244
|
+
if (isErrorType(c, expressionType))
|
|
245
|
+
return resolveErrorCall(c, node);
|
|
246
|
+
if ((expressionType.flags & 1 /* TypeFlags.Any */) !== 0) {
|
|
247
|
+
if (node.typeArguments !== undefined && node.typeArguments.nodes.length !== 0)
|
|
248
|
+
c.error(node, 523 /* Diagnostics.Untyped_function_calls_may_not_accept_type_arguments */);
|
|
249
|
+
return resolveUntypedCall(c, node);
|
|
250
|
+
}
|
|
251
|
+
const constructSignatures = getSignaturesOfType(c, expressionType, 1 /* SignatureKind.Construct */);
|
|
252
|
+
if (constructSignatures.length !== 0) {
|
|
253
|
+
if (!isConstructorAccessible(c, node, constructSignatures[0]))
|
|
254
|
+
return resolveErrorCall(c, node);
|
|
255
|
+
if (someSignature(constructSignatures, (s) => (s.flags & 8 /* SignatureFlags.Abstract */) !== 0)) {
|
|
256
|
+
c.error(node, 671 /* Diagnostics.Cannot_create_an_instance_of_an_abstract_class */);
|
|
257
|
+
return resolveErrorCall(c, node);
|
|
258
|
+
}
|
|
259
|
+
return resolveCall(c, node, constructSignatures, checkMode, 0 /* SignatureFlags.None */, undefined);
|
|
260
|
+
}
|
|
261
|
+
// A function without construct signatures is called as a function.
|
|
262
|
+
const callSignatures = getSignaturesOfType(c, expressionType, 0 /* SignatureKind.Call */);
|
|
263
|
+
if (callSignatures.length !== 0) {
|
|
264
|
+
const signature = resolveCall(c, node, callSignatures, checkMode, 0 /* SignatureFlags.None */, undefined);
|
|
265
|
+
if (!c.noImplicitAny) {
|
|
266
|
+
if (signature.declaration !== undefined && getReturnTypeOfSignature(c, signature) !== c.voidType)
|
|
267
|
+
c.error(node, 526 /* Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword */);
|
|
268
|
+
if (getThisTypeOfSignature(c, signature) === c.voidType)
|
|
269
|
+
c.error(node, 813 /* Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void */);
|
|
270
|
+
}
|
|
271
|
+
return signature;
|
|
272
|
+
}
|
|
273
|
+
invocationError(c, node.expression, expressionType, 1 /* SignatureKind.Construct */);
|
|
274
|
+
return resolveErrorCall(c, node);
|
|
275
|
+
}
|
|
276
|
+
function someSignature(signatures, f) {
|
|
277
|
+
for (const sig of signatures) {
|
|
278
|
+
const composite = sig.composite;
|
|
279
|
+
if (composite === undefined) {
|
|
280
|
+
if (f(sig))
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
else if (composite.isUnion) {
|
|
284
|
+
for (const s of composite.signatures)
|
|
285
|
+
if (f(s))
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
function someGenericFunctionReturningFunction(c, signatures) {
|
|
292
|
+
for (const s of signatures)
|
|
293
|
+
if (isGenericFunctionReturningFunction(c, s))
|
|
294
|
+
return true;
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
function someContextSensitive(c, nodes) {
|
|
298
|
+
for (const n of nodes)
|
|
299
|
+
if (isContextSensitive(c, n))
|
|
300
|
+
return true;
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
function resolveTaggedTemplateExpression(c, node, checkMode) {
|
|
304
|
+
const tag = node.tag;
|
|
305
|
+
const tagType = checkExpression(c, tag);
|
|
306
|
+
const apparentType = getApparentType(c, tagType);
|
|
307
|
+
if (isErrorType(c, apparentType))
|
|
308
|
+
return resolveErrorCall(c, node);
|
|
309
|
+
const callSignatures = getSignaturesOfType(c, apparentType, 0 /* SignatureKind.Call */);
|
|
310
|
+
const numConstructSignatures = getSignaturesOfType(c, apparentType, 1 /* SignatureKind.Construct */).length;
|
|
311
|
+
if (isUntypedFunctionCall(c, tagType, apparentType, callSignatures.length, numConstructSignatures))
|
|
312
|
+
return resolveUntypedCall(c, node);
|
|
313
|
+
if (callSignatures.length === 0) {
|
|
314
|
+
if (node.parent !== undefined && node.parent.kind === 210 /* SyntaxKind.ArrayLiteralExpression */) {
|
|
315
|
+
c.error(tag, 928 /* Diagnostics.It_is_likely_that_you_are_missing_a_comma_to_separate_these_two_template_expressions_They_form_a_tagged_template_expression_which_cannot_be_invoked */);
|
|
316
|
+
return resolveErrorCall(c, node);
|
|
317
|
+
}
|
|
318
|
+
invocationError(c, tag, apparentType, 0 /* SignatureKind.Call */);
|
|
319
|
+
return resolveErrorCall(c, node);
|
|
320
|
+
}
|
|
321
|
+
return resolveCall(c, node, callSignatures, checkMode, 0 /* SignatureFlags.None */, undefined);
|
|
322
|
+
}
|
|
323
|
+
/** A decorator is called with the arguments the runtime passes for its declaration. */
|
|
324
|
+
function resolveDecorator(c, node, checkMode) {
|
|
325
|
+
if (!canHaveDecorators(node.parent))
|
|
326
|
+
return resolveErrorCall(c, node);
|
|
327
|
+
const expression = node.expression;
|
|
328
|
+
const funcType = checkExpression(c, expression);
|
|
329
|
+
const apparentType = getApparentType(c, funcType);
|
|
330
|
+
if (isErrorType(c, apparentType))
|
|
331
|
+
return resolveErrorCall(c, node);
|
|
332
|
+
const callSignatures = getSignaturesOfType(c, apparentType, 0 /* SignatureKind.Call */);
|
|
333
|
+
const numConstructSignatures = getSignaturesOfType(c, apparentType, 1 /* SignatureKind.Construct */).length;
|
|
334
|
+
if (isUntypedFunctionCall(c, funcType, apparentType, callSignatures.length, numConstructSignatures))
|
|
335
|
+
return resolveUntypedCall(c, node);
|
|
336
|
+
if (isPotentiallyUncalledDecorator(c, node, callSignatures) &&
|
|
337
|
+
expression.kind !== 218 /* SyntaxKind.ParenthesizedExpression */) {
|
|
338
|
+
c.error(node, 265 /* Diagnostics.X_0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0 */, getUncalledDecoratorText(node));
|
|
339
|
+
return resolveErrorCall(c, node);
|
|
340
|
+
}
|
|
341
|
+
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
|
342
|
+
if (callSignatures.length === 0) {
|
|
343
|
+
c.addDiagnostic(chainDiagnostic(getInvocationErrorDetails(c, expression, apparentType, true), headMessage));
|
|
344
|
+
return resolveErrorCall(c, node);
|
|
345
|
+
}
|
|
346
|
+
if (getDecoratorCallSignature(c, node) === undefined)
|
|
347
|
+
return resolveErrorCall(c, node);
|
|
348
|
+
return resolveCall(c, node, callSignatures, checkMode, 0 /* SignatureFlags.None */, headMessage);
|
|
349
|
+
}
|
|
350
|
+
/** Whether a call is untyped: to `any`, or to a `Function` without signatures. */
|
|
351
|
+
export function isUntypedFunctionCall(c, funcType, apparentFuncType, numCallSignatures, numConstructSignatures) {
|
|
352
|
+
return ((funcType.flags & 1 /* TypeFlags.Any */) !== 0 ||
|
|
353
|
+
((apparentFuncType.flags & 1 /* TypeFlags.Any */) !== 0 && (funcType.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) ||
|
|
354
|
+
(numCallSignatures === 0 &&
|
|
355
|
+
numConstructSignatures === 0 &&
|
|
356
|
+
(apparentFuncType.flags & 134217728 /* TypeFlags.Union */) === 0 &&
|
|
357
|
+
(getReducedType(c, apparentFuncType).flags & 262144 /* TypeFlags.Never */) === 0 &&
|
|
358
|
+
isTypeAssignableTo(c, funcType, c.globalFunctionType)));
|
|
359
|
+
}
|
|
360
|
+
export function resolveUntypedCall(c, node) {
|
|
361
|
+
// Type arguments are checked even though untyped calls can't accept them.
|
|
362
|
+
if (node.kind === 214 /* SyntaxKind.CallExpression */ ||
|
|
363
|
+
node.kind === 215 /* SyntaxKind.NewExpression */ ||
|
|
364
|
+
node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */ ||
|
|
365
|
+
isJsxOpeningLikeElement(node))
|
|
366
|
+
for (const t of getCallTypeArguments(node))
|
|
367
|
+
checkSourceElement(c, t);
|
|
368
|
+
if (node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */) {
|
|
369
|
+
const template = node.template;
|
|
370
|
+
if (template.kind === 229 /* SyntaxKind.TemplateExpression */)
|
|
371
|
+
for (const span of template.templateSpans.nodes)
|
|
372
|
+
checkExpression(c, getExpression(span));
|
|
373
|
+
}
|
|
374
|
+
else
|
|
375
|
+
for (const arg of getCallArgumentNodes(node))
|
|
376
|
+
checkExpression(c, arg);
|
|
377
|
+
return c.anySignature;
|
|
378
|
+
}
|
|
379
|
+
export function resolveErrorCall(c, node) {
|
|
380
|
+
resolveUntypedCall(c, node);
|
|
381
|
+
return c.unknownSignature;
|
|
382
|
+
}
|
|
383
|
+
function invocationError(c, errorTarget, apparentType, kind) {
|
|
384
|
+
const isCall = kind === 0 /* SignatureKind.Call */;
|
|
385
|
+
const parent = errorTarget.parent;
|
|
386
|
+
const target = errorTarget.kind === 212 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
387
|
+
parent !== undefined &&
|
|
388
|
+
parent.kind === 214 /* SyntaxKind.CallExpression */
|
|
389
|
+
? getName(errorTarget)
|
|
390
|
+
: errorTarget;
|
|
391
|
+
let headMessage = isCall
|
|
392
|
+
? 525 /* Diagnostics.This_expression_is_not_callable */
|
|
393
|
+
: 527 /* Diagnostics.This_expression_is_not_constructable */;
|
|
394
|
+
// A get accessor called as a function.
|
|
395
|
+
if (parent !== undefined &&
|
|
396
|
+
parent.kind === 214 /* SyntaxKind.CallExpression */ &&
|
|
397
|
+
parent.arguments.nodes.length === 0) {
|
|
398
|
+
const resolvedSymbol = c.resolvedSymbols.get(errorTarget.id);
|
|
399
|
+
if (resolvedSymbol !== undefined && (resolvedSymbol.flags & 32768 /* SymbolFlags.GetAccessor */) !== 0)
|
|
400
|
+
headMessage =
|
|
401
|
+
1386 /* Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without */;
|
|
402
|
+
}
|
|
403
|
+
c.addDiagnostic(chainDiagnostic(getInvocationErrorDetails(c, target, apparentType, isCall), headMessage));
|
|
404
|
+
}
|
|
405
|
+
function getInvocationErrorDetails(c, target, apparentType, isCall) {
|
|
406
|
+
const kind = isCall ? 0 /* SignatureKind.Call */ : 1 /* SignatureKind.Construct */;
|
|
407
|
+
if ((apparentType.flags & 134217728 /* TypeFlags.Union */) === 0)
|
|
408
|
+
return createDiagnosticForNode(target, isCall ? 889 /* Diagnostics.Type_0_has_no_call_signatures */ : 893 /* Diagnostics.Type_0_has_no_construct_signatures */, [typeToString(c, apparentType)]);
|
|
409
|
+
let diagnostic = undefined;
|
|
410
|
+
let hasSignatures = false;
|
|
411
|
+
for (const constituent of typesOf(apparentType)) {
|
|
412
|
+
if (getSignaturesOfType(c, constituent, kind).length !== 0) {
|
|
413
|
+
hasSignatures = true;
|
|
414
|
+
// With an error already found, "no constituent is callable" can't apply.
|
|
415
|
+
if (diagnostic !== undefined)
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
else if (diagnostic === undefined) {
|
|
419
|
+
// The first non-callable constituent.
|
|
420
|
+
diagnostic = chainDiagnostic(createDiagnosticForNode(target, isCall ? 889 /* Diagnostics.Type_0_has_no_call_signatures */ : 893 /* Diagnostics.Type_0_has_no_construct_signatures */, [typeToString(c, constituent)]), isCall
|
|
421
|
+
? 888 /* Diagnostics.Not_all_constituents_of_type_0_are_callable */
|
|
422
|
+
: 892 /* Diagnostics.Not_all_constituents_of_type_0_are_constructable */, typeToString(c, apparentType));
|
|
423
|
+
if (hasSignatures)
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (!hasSignatures)
|
|
428
|
+
return createDiagnosticForNode(target, isCall ? 887 /* Diagnostics.No_constituent_of_type_0_is_callable */ : 891 /* Diagnostics.No_constituent_of_type_0_is_constructable */, [typeToString(c, apparentType)]);
|
|
429
|
+
return (diagnostic ??
|
|
430
|
+
createDiagnosticForNode(target, isCall
|
|
431
|
+
? 890 /* Diagnostics.Each_member_of_the_union_type_0_has_signatures_but_none_of_those_signatures_are_compatible_with_each_other */
|
|
432
|
+
: 894 /* Diagnostics.Each_member_of_the_union_type_0_has_construct_signatures_but_none_of_those_signatures_are_compatible_with_each_other */, [typeToString(c, apparentType)]));
|
|
433
|
+
}
|
|
434
|
+
function checkNonNullTypeForCall(c, t, node) {
|
|
435
|
+
return checkNonNullTypeEx(c, t, node, true);
|
|
436
|
+
}
|
|
437
|
+
function skippedGenericFunction(c, node, checkMode) {
|
|
438
|
+
if ((checkMode & 2 /* CheckMode.Inferential */) !== 0) {
|
|
439
|
+
// Mark the inference context so the caller knows to retry with SkipGenericFunctions.
|
|
440
|
+
const context = getInferenceContext(c, node);
|
|
441
|
+
if (context !== undefined)
|
|
442
|
+
context.flags |= 4 /* InferenceFlags.SkippedGenericFunction */;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function isGenericFunctionReturningFunction(c, signature) {
|
|
446
|
+
return signature.typeParameters.length !== 0 && isFunctionType(c, getReturnTypeOfSignature(c, signature));
|
|
447
|
+
}
|
|
448
|
+
function isFunctionType(c, t) {
|
|
449
|
+
return (t.flags & 1048576 /* TypeFlags.Object */) !== 0 && getSignaturesOfType(c, t, 0 /* SignatureKind.Call */).length > 0;
|
|
450
|
+
}
|
|
451
|
+
// ---- Arguments
|
|
452
|
+
/** An argument with a known type: a tagged template's strings, or an element of a spread tuple. */
|
|
453
|
+
export class SyntheticExpression extends Node {
|
|
454
|
+
type;
|
|
455
|
+
isSpread;
|
|
456
|
+
tupleNameSource;
|
|
457
|
+
constructor(parent, type, isSpread, tupleNameSource) {
|
|
458
|
+
super(238 /* SyntaxKind.SyntheticExpression */);
|
|
459
|
+
this.parent = parent;
|
|
460
|
+
this.pos = parent.pos;
|
|
461
|
+
this.end = parent.end;
|
|
462
|
+
this.type = type;
|
|
463
|
+
this.isSpread = isSpread;
|
|
464
|
+
this.tupleNameSource = tupleNameSource;
|
|
465
|
+
}
|
|
466
|
+
forEachChild(_visitor) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
setParentOfChildren() { }
|
|
470
|
+
deepClone() {
|
|
471
|
+
return new SyntheticExpression(this.parent, this.type, this.isSpread, this.tupleNameSource);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function getCallArgumentNodes(node) {
|
|
475
|
+
if (node.kind === 227 /* SyntaxKind.BinaryExpression */)
|
|
476
|
+
return [node.left];
|
|
477
|
+
if (node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */) {
|
|
478
|
+
const template = node.template;
|
|
479
|
+
const args = [template];
|
|
480
|
+
if (template.kind === 229 /* SyntaxKind.TemplateExpression */)
|
|
481
|
+
for (const span of template.templateSpans.nodes)
|
|
482
|
+
args.push(getExpression(span));
|
|
483
|
+
return args;
|
|
484
|
+
}
|
|
485
|
+
const list = getArgumentList(node);
|
|
486
|
+
return list !== undefined ? list.nodes : [];
|
|
487
|
+
}
|
|
488
|
+
/** The arguments of a call, with spreads of tuples expanded and a tagged template's strings first. */
|
|
489
|
+
export function getEffectiveCallArguments(c, node) {
|
|
490
|
+
// A fragment's attributes have no `children` yet, like those of `<React.Fragment>`.
|
|
491
|
+
if (node.kind === 290 /* SyntaxKind.JsxOpeningFragment */)
|
|
492
|
+
return [new SyntheticExpression(node, c.emptyFreshJsxObjectType, false, undefined)];
|
|
493
|
+
if (isJsxOpeningLikeElement(node))
|
|
494
|
+
return getEffectiveJsxArguments(node);
|
|
495
|
+
if (node.kind === 171 /* SyntaxKind.Decorator */) {
|
|
496
|
+
// One synthetic argument per parameter of the decorator's call signature.
|
|
497
|
+
const expression = node.expression;
|
|
498
|
+
const args = [];
|
|
499
|
+
for (const t of getEffectiveDecoratorArgumentTypes(c, node))
|
|
500
|
+
args.push(new SyntheticExpression(expression, t, false, undefined));
|
|
501
|
+
return args;
|
|
502
|
+
}
|
|
503
|
+
if (node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */) {
|
|
504
|
+
const template = node.template;
|
|
505
|
+
const args = [new SyntheticExpression(template, getGlobalTemplateStringsArrayType(c), false, undefined)];
|
|
506
|
+
if (template.kind === 229 /* SyntaxKind.TemplateExpression */)
|
|
507
|
+
for (const span of template.templateSpans.nodes)
|
|
508
|
+
args.push(getExpression(span));
|
|
509
|
+
return args;
|
|
510
|
+
}
|
|
511
|
+
const args = getCallArgumentNodes(node);
|
|
512
|
+
const spreadIndex = getSpreadArgumentIndex(args);
|
|
513
|
+
if (spreadIndex < 0)
|
|
514
|
+
return args;
|
|
515
|
+
// Spreads of tuple types become synthetic arguments, one per element.
|
|
516
|
+
const effectiveArgs = args.slice(0, spreadIndex);
|
|
517
|
+
for (let i = spreadIndex; i < args.length; i++) {
|
|
518
|
+
const arg = args[i];
|
|
519
|
+
// Spread expressions never have a contextual type, so caching is safe.
|
|
520
|
+
const spreadType = arg.kind === 231 /* SyntaxKind.SpreadElement */
|
|
521
|
+
? c.flowLoopStack.length !== 0
|
|
522
|
+
? checkExpression(c, arg.expression)
|
|
523
|
+
: checkExpressionCached(c, arg.expression)
|
|
524
|
+
: undefined;
|
|
525
|
+
if (spreadType !== undefined && isTupleType(spreadType)) {
|
|
526
|
+
const elementTypes = getElementTypes(c, spreadType);
|
|
527
|
+
const elementInfos = tupleTargetOf(spreadType).elementInfos;
|
|
528
|
+
for (let j = 0; j < elementTypes.length; j++) {
|
|
529
|
+
const flags = elementInfos[j].flags;
|
|
530
|
+
effectiveArgs.push(new SyntheticExpression(arg, (flags & 4 /* ElementFlags.Rest */) !== 0 ? createArrayType(c, elementTypes[j]) : elementTypes[j], (flags & 12 /* ElementFlags.Variable */) !== 0, elementInfos[j].labeledDeclaration));
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
else
|
|
534
|
+
effectiveArgs.push(arg);
|
|
535
|
+
}
|
|
536
|
+
return effectiveArgs;
|
|
537
|
+
}
|
|
538
|
+
/** Checks an argument with the parameter type as its contextual type. */
|
|
539
|
+
function checkArgument(c, arg, paramType, context, checkMode) {
|
|
540
|
+
if (arg.kind === 238 /* SyntaxKind.SyntheticExpression */)
|
|
541
|
+
return checkSyntheticExpression(c, arg);
|
|
542
|
+
return checkExpressionWithContextualType(c, arg, paramType, context, checkMode);
|
|
543
|
+
}
|
|
544
|
+
/** A synthetic argument's type; a spread one stands for its elements. */
|
|
545
|
+
function checkSyntheticExpression(c, node) {
|
|
546
|
+
return node.isSpread
|
|
547
|
+
? getIndexedAccessTypeEx(c, node.type, c.numberType, 0 /* AccessFlags.None */, undefined, undefined)
|
|
548
|
+
: node.type;
|
|
549
|
+
}
|
|
550
|
+
function getSpreadArgumentIndex(args) {
|
|
551
|
+
for (let i = 0; i < args.length; i++)
|
|
552
|
+
if (isSpreadArgument(args[i]))
|
|
553
|
+
return i;
|
|
554
|
+
return -1;
|
|
555
|
+
}
|
|
556
|
+
function isSpreadArgument(arg) {
|
|
557
|
+
return (arg.kind === 231 /* SyntaxKind.SpreadElement */ ||
|
|
558
|
+
(arg.kind === 238 /* SyntaxKind.SyntheticExpression */ && arg.isSpread));
|
|
559
|
+
}
|
|
560
|
+
/** The rest arguments from `index` as a tuple, or an array for a trailing spread to a rest parameter. */
|
|
561
|
+
function getSpreadArgumentType(c, call, args, index, argCount, restType, context, checkMode) {
|
|
562
|
+
const inConstContext = isConstTypeVariable(c, restType, 0);
|
|
563
|
+
if (argCount > 0 && index >= argCount - 1) {
|
|
564
|
+
const arg = args[argCount - 1];
|
|
565
|
+
if (isSpreadArgument(arg)) {
|
|
566
|
+
// A spread in the last position to a rest parameter: both are `...x` forms.
|
|
567
|
+
const spreadType = arg.kind === 238 /* SyntaxKind.SyntheticExpression */
|
|
568
|
+
? arg.type
|
|
569
|
+
: checkExpressionWithContextualType(c, arg.expression, restType, context, checkMode);
|
|
570
|
+
if (isArrayLikeType(c, spreadType))
|
|
571
|
+
return getMutableArrayOrTupleType(c, spreadType);
|
|
572
|
+
const errorNode = arg.kind === 231 /* SyntaxKind.SpreadElement */ ? arg.expression : arg;
|
|
573
|
+
return createArrayTypeEx(c, checkIteratedTypeOrElementType(c, 33 /* IterationUse.Spread */, spreadType, c.undefinedType, errorNode), inConstContext);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const types = [];
|
|
577
|
+
const infos = [];
|
|
578
|
+
for (let i = index; i < argCount; i++) {
|
|
579
|
+
const arg = args[i];
|
|
580
|
+
if (isSpreadArgument(arg)) {
|
|
581
|
+
const spreadType = arg.kind === 238 /* SyntaxKind.SyntheticExpression */
|
|
582
|
+
? arg.type
|
|
583
|
+
: checkExpression(c, arg.expression);
|
|
584
|
+
if (isArrayLikeType(c, spreadType)) {
|
|
585
|
+
types.push(spreadType);
|
|
586
|
+
infos.push(new TupleElementInfo(8 /* ElementFlags.Variadic */, undefined));
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
const errorNode = arg.kind === 231 /* SyntaxKind.SpreadElement */ ? arg.expression : arg;
|
|
590
|
+
types.push(checkIteratedTypeOrElementType(c, 33 /* IterationUse.Spread */, spreadType, c.undefinedType, errorNode));
|
|
591
|
+
infos.push(new TupleElementInfo(4 /* ElementFlags.Rest */, undefined));
|
|
592
|
+
}
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
const contextualType = isTupleType(restType)
|
|
596
|
+
? (getContextualTypeForElementExpression(c, restType, i - index, argCount - index, -1, -1) ?? c.unknownType)
|
|
597
|
+
: getIndexedAccessTypeEx(c, restType, getNumberLiteralType(c, i - index), 256 /* AccessFlags.Contextual */, undefined, undefined);
|
|
598
|
+
const argType = checkArgument(c, arg, contextualType, context, checkMode);
|
|
599
|
+
const hasPrimitiveContextualType = inConstContext ||
|
|
600
|
+
maybeTypeOfKind(contextualType, 12713980 /* TypeFlags.Primitive */ | 2097152 /* TypeFlags.Index */ | 4194304 /* TypeFlags.TemplateLiteral */ | 8388608 /* TypeFlags.StringMapping */);
|
|
601
|
+
types.push(hasPrimitiveContextualType ? getRegularTypeOfLiteralType(c, argType) : getWidenedLiteralType(c, argType));
|
|
602
|
+
infos.push(new TupleElementInfo(1 /* ElementFlags.Required */, arg.kind === 238 /* SyntaxKind.SyntheticExpression */ ? arg.tupleNameSource : undefined));
|
|
603
|
+
}
|
|
604
|
+
return createTupleTypeEx(c, types, infos, inConstContext && !someType(restType, (t) => isMutableArrayLikeType(c, t)));
|
|
605
|
+
}
|
|
606
|
+
/** The type of the arguments from `index` on, for the rest parameter of an immediately invoked function. */
|
|
607
|
+
export function getRestArgumentsType(c, call, args, index) {
|
|
608
|
+
return getSpreadArgumentType(c, call, args, index, args.length, c.anyType, undefined, 0 /* CheckMode.Normal */);
|
|
609
|
+
}
|
|
610
|
+
function getMutableArrayOrTupleType(c, t) {
|
|
611
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
612
|
+
return mapType(c, t, (u) => getMutableArrayOrTupleType(c, u));
|
|
613
|
+
if ((t.flags & 1 /* TypeFlags.Any */) !== 0 || isMutableArrayOrTuple(c, getBaseConstraintOrType(c, t)))
|
|
614
|
+
return t;
|
|
615
|
+
if (isTupleType(t))
|
|
616
|
+
return createTupleTypeEx(c, getElementTypes(c, t), tupleTargetOf(t).elementInfos, false);
|
|
617
|
+
return createTupleTypeEx(c, [t], [new TupleElementInfo(8 /* ElementFlags.Variadic */, undefined)], false);
|
|
618
|
+
}
|
|
619
|
+
// ---- Overload resolution
|
|
620
|
+
/** The state of one `resolveCall`, shared by its `chooseOverload` passes. */
|
|
621
|
+
class CallState {
|
|
622
|
+
node;
|
|
623
|
+
typeArguments;
|
|
624
|
+
args;
|
|
625
|
+
candidates;
|
|
626
|
+
argCheckMode = 0 /* CheckMode.Normal */;
|
|
627
|
+
isSingleNonGenericCandidate = false;
|
|
628
|
+
candidatesForArgumentError = [];
|
|
629
|
+
candidateForArgumentArityError = undefined;
|
|
630
|
+
candidateForTypeArgumentError = undefined;
|
|
631
|
+
constructor(node, typeArguments, args, candidates) {
|
|
632
|
+
this.node = node;
|
|
633
|
+
this.typeArguments = typeArguments;
|
|
634
|
+
this.args = args;
|
|
635
|
+
this.candidates = candidates;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function getCallTypeArguments(node) {
|
|
639
|
+
if (node.kind === 290 /* SyntaxKind.JsxOpeningFragment */ || node.kind === 171 /* SyntaxKind.Decorator */)
|
|
640
|
+
return [];
|
|
641
|
+
if (node.kind === 214 /* SyntaxKind.CallExpression */ && node.expression.kind === 107 /* SyntaxKind.SuperKeyword */)
|
|
642
|
+
return [];
|
|
643
|
+
const list = getTypeArgumentList(node);
|
|
644
|
+
return list !== undefined ? list.nodes : [];
|
|
645
|
+
}
|
|
646
|
+
export function resolveCall(c, node, signatures, checkMode, callChainFlags, headMessage) {
|
|
647
|
+
const typeArguments = getCallTypeArguments(node);
|
|
648
|
+
for (const t of typeArguments)
|
|
649
|
+
checkSourceElement(c, t);
|
|
650
|
+
const candidates = reorderCandidates(c, signatures, callChainFlags);
|
|
651
|
+
if (candidates.length === 0)
|
|
652
|
+
return c.unknownSignature;
|
|
653
|
+
const s = new CallState(node, typeArguments, getEffectiveCallArguments(c, node), candidates);
|
|
654
|
+
// Context-sensitive arguments are excluded from a first inference and applicability pass, then
|
|
655
|
+
// included in a second pass with their contextual types fixed.
|
|
656
|
+
s.isSingleNonGenericCandidate = candidates.length === 1 && candidates[0].typeParameters.length === 0;
|
|
657
|
+
// Decorator arguments are synthetic, so never context sensitive.
|
|
658
|
+
if (node.kind !== 171 /* SyntaxKind.Decorator */ && !s.isSingleNonGenericCandidate && someContextSensitive(c, s.args))
|
|
659
|
+
s.argCheckMode = 4 /* CheckMode.SkipContextSensitive */;
|
|
660
|
+
// A subtype pass picks the best overload; assignability decides whether the call is an error.
|
|
661
|
+
let result = undefined;
|
|
662
|
+
if (candidates.length > 1)
|
|
663
|
+
result = chooseOverload(c, s, c.subtypeRelation);
|
|
664
|
+
if (result === undefined)
|
|
665
|
+
result = chooseOverload(c, s, c.assignableRelation);
|
|
666
|
+
if (result !== undefined)
|
|
667
|
+
return result;
|
|
668
|
+
result = getCandidateForOverloadFailure(c, node, s.candidates, s.args, checkMode);
|
|
669
|
+
// Cache now so that error reporting below handles circularities like getResolvedSignature would.
|
|
670
|
+
c.resolvedSignatures.set(node.id, result);
|
|
671
|
+
reportCallResolutionErrors(c, s, signatures, headMessage);
|
|
672
|
+
return result;
|
|
673
|
+
}
|
|
674
|
+
export function reorderCandidates(c, signatures, callChainFlags) {
|
|
675
|
+
let lastParent = undefined;
|
|
676
|
+
let lastSymbol = undefined;
|
|
677
|
+
let index = 0;
|
|
678
|
+
let cutoffIndex = 0;
|
|
679
|
+
let spliceIndex;
|
|
680
|
+
let specializedIndex = -1;
|
|
681
|
+
const result = [];
|
|
682
|
+
for (let signature of signatures) {
|
|
683
|
+
const declaration = signature.declaration;
|
|
684
|
+
const symbol = declaration !== undefined ? getSymbolOfDeclaration(c, declaration) : undefined;
|
|
685
|
+
const parent = declaration !== undefined ? declaration.parent : undefined;
|
|
686
|
+
if (lastSymbol === undefined || symbol === lastSymbol) {
|
|
687
|
+
if (lastParent !== undefined && parent === lastParent)
|
|
688
|
+
index = index + 1;
|
|
689
|
+
else {
|
|
690
|
+
lastParent = parent;
|
|
691
|
+
index = cutoffIndex;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
// A different symbol: later reorderings must not move signatures before the cutoff.
|
|
696
|
+
index = result.length;
|
|
697
|
+
cutoffIndex = result.length;
|
|
698
|
+
lastParent = parent;
|
|
699
|
+
}
|
|
700
|
+
lastSymbol = symbol;
|
|
701
|
+
// Specialized signatures go before non-specialized ones regardless of the cutoff.
|
|
702
|
+
if ((signature.flags & 2 /* SignatureFlags.HasLiteralTypes */) !== 0) {
|
|
703
|
+
specializedIndex++;
|
|
704
|
+
spliceIndex = specializedIndex;
|
|
705
|
+
cutoffIndex++;
|
|
706
|
+
}
|
|
707
|
+
else
|
|
708
|
+
spliceIndex = index;
|
|
709
|
+
if (callChainFlags !== 0)
|
|
710
|
+
signature = getOptionalCallSignature(c, signature, callChainFlags);
|
|
711
|
+
result.splice(spliceIndex, 0, signature);
|
|
712
|
+
}
|
|
713
|
+
return result;
|
|
714
|
+
}
|
|
715
|
+
function getOptionalCallSignature(c, signature, callChainFlags) {
|
|
716
|
+
if ((signature.flags & 48 /* SignatureFlags.CallChainFlags */) === callChainFlags)
|
|
717
|
+
return signature;
|
|
718
|
+
const key = callChainFlags === 16 /* SignatureFlags.IsInnerCallChain */ ? 'inner' : 'outer';
|
|
719
|
+
let cache = c.inferenceCaches.optionalCallSignatures.get(signature);
|
|
720
|
+
if (cache === undefined) {
|
|
721
|
+
cache = new Map();
|
|
722
|
+
c.inferenceCaches.optionalCallSignatures.set(signature, cache);
|
|
723
|
+
}
|
|
724
|
+
let result = cache.get(key);
|
|
725
|
+
if (result === undefined) {
|
|
726
|
+
result = cloneSignature(c, signature);
|
|
727
|
+
result.flags |= callChainFlags;
|
|
728
|
+
cache.set(key, result);
|
|
729
|
+
}
|
|
730
|
+
return result;
|
|
731
|
+
}
|
|
732
|
+
function chooseOverload(c, s, relation) {
|
|
733
|
+
s.candidatesForArgumentError = [];
|
|
734
|
+
s.candidateForArgumentArityError = undefined;
|
|
735
|
+
s.candidateForTypeArgumentError = undefined;
|
|
736
|
+
if (s.isSingleNonGenericCandidate) {
|
|
737
|
+
const candidate = s.candidates[0];
|
|
738
|
+
if (s.typeArguments.length !== 0 || !hasCorrectArity(c, s.node, s.args, candidate))
|
|
739
|
+
return undefined;
|
|
740
|
+
if (!isSignatureApplicable(c, s.node, s.args, candidate, relation, 0 /* CheckMode.Normal */, false, undefined)) {
|
|
741
|
+
s.candidatesForArgumentError = [candidate];
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
return candidate;
|
|
745
|
+
}
|
|
746
|
+
for (let candidateIndex = 0; candidateIndex < s.candidates.length; candidateIndex++) {
|
|
747
|
+
const candidate = s.candidates[candidateIndex];
|
|
748
|
+
if (!hasCorrectTypeArgumentArity(c, candidate, s.typeArguments) || !hasCorrectArity(c, s.node, s.args, candidate))
|
|
749
|
+
continue;
|
|
750
|
+
let checkCandidate;
|
|
751
|
+
let inferenceContext = undefined;
|
|
752
|
+
if (candidate.typeParameters.length !== 0) {
|
|
753
|
+
let typeArgumentTypes;
|
|
754
|
+
if (s.typeArguments.length !== 0) {
|
|
755
|
+
typeArgumentTypes = checkTypeArguments(c, candidate, s.typeArguments, false, undefined);
|
|
756
|
+
if (typeArgumentTypes === undefined) {
|
|
757
|
+
s.candidateForTypeArgumentError = candidate;
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
inferenceContext = createInferenceContext(c, candidate.typeParameters, candidate, isInJSFile(s.node) ? 2 /* InferenceFlags.AnyDefault */ : 0 /* InferenceFlags.None */, undefined);
|
|
763
|
+
typeArgumentTypes = inferTypeArguments(c, s.node, candidate, s.args, s.argCheckMode | 8 /* CheckMode.SkipGenericFunctions */, inferenceContext);
|
|
764
|
+
if ((inferenceContext.flags & 4 /* InferenceFlags.SkippedGenericFunction */) !== 0)
|
|
765
|
+
s.argCheckMode |= 8 /* CheckMode.SkipGenericFunctions */;
|
|
766
|
+
}
|
|
767
|
+
checkCandidate = getSignatureInstantiationWithInferredTypeParameters(c, candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext !== undefined ? inferenceContext.inferredTypeParameters : undefined);
|
|
768
|
+
// A generic rest type may instantiate to a different arity.
|
|
769
|
+
if (getNonArrayRestType(c, candidate) !== undefined && !hasCorrectArity(c, s.node, s.args, checkCandidate)) {
|
|
770
|
+
s.candidateForArgumentArityError = checkCandidate;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
else
|
|
775
|
+
checkCandidate = candidate;
|
|
776
|
+
if (!isSignatureApplicable(c, s.node, s.args, checkCandidate, relation, s.argCheckMode, false, undefined)) {
|
|
777
|
+
s.candidatesForArgumentError.push(checkCandidate);
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
if (s.argCheckMode !== 0 /* CheckMode.Normal */) {
|
|
781
|
+
// Include the excluded context-sensitive arguments from now on, with a second round of
|
|
782
|
+
// inference and applicability checking for this candidate.
|
|
783
|
+
s.argCheckMode = 0 /* CheckMode.Normal */;
|
|
784
|
+
if (inferenceContext !== undefined) {
|
|
785
|
+
const typeArgumentTypes = inferTypeArguments(c, s.node, candidate, s.args, s.argCheckMode, inferenceContext);
|
|
786
|
+
checkCandidate = getSignatureInstantiationWithInferredTypeParameters(c, candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
|
|
787
|
+
if (getNonArrayRestType(c, candidate) !== undefined && !hasCorrectArity(c, s.node, s.args, checkCandidate)) {
|
|
788
|
+
s.candidateForArgumentArityError = checkCandidate;
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (!isSignatureApplicable(c, s.node, s.args, checkCandidate, relation, s.argCheckMode, false, undefined)) {
|
|
793
|
+
s.candidatesForArgumentError.push(checkCandidate);
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
s.candidates[candidateIndex] = checkCandidate;
|
|
798
|
+
return checkCandidate;
|
|
799
|
+
}
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
function isInJSFile(node) {
|
|
803
|
+
return node !== undefined && (node.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0;
|
|
804
|
+
}
|
|
805
|
+
function hasCorrectArity(c, node, args, signature) {
|
|
806
|
+
if (node.kind === 290 /* SyntaxKind.JsxOpeningFragment */)
|
|
807
|
+
return true;
|
|
808
|
+
let argCount;
|
|
809
|
+
let callIsIncomplete = false;
|
|
810
|
+
let effectiveParameterCount = getParameterCount(c, signature);
|
|
811
|
+
let effectiveMinimumArguments = getMinArgumentCount(c, signature);
|
|
812
|
+
if (isJsxOpeningLikeElement(node)) {
|
|
813
|
+
// An incomplete element is lenient.
|
|
814
|
+
if (getAttributesOf(node).end === node.end)
|
|
815
|
+
return true;
|
|
816
|
+
argCount = effectiveMinimumArguments === 0 ? args.length : 1;
|
|
817
|
+
// Class components may have argumentless constructors; their props come from the instance.
|
|
818
|
+
if (args.length !== 0)
|
|
819
|
+
effectiveParameterCount = 1;
|
|
820
|
+
// A component's extra parameters, such as a legacy context, are provided by the library.
|
|
821
|
+
effectiveMinimumArguments = Math.min(effectiveMinimumArguments, 1);
|
|
822
|
+
}
|
|
823
|
+
else if (node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */) {
|
|
824
|
+
argCount = args.length;
|
|
825
|
+
const template = node.template;
|
|
826
|
+
if (template.kind === 229 /* SyntaxKind.TemplateExpression */) {
|
|
827
|
+
// A template without a tail literal makes the call incomplete.
|
|
828
|
+
const spans = template.templateSpans.nodes;
|
|
829
|
+
const literal = spans[spans.length - 1].literal;
|
|
830
|
+
callIsIncomplete = literal.end === literal.pos || isUnterminatedLiteral(literal);
|
|
831
|
+
}
|
|
832
|
+
else
|
|
833
|
+
callIsIncomplete = isUnterminatedLiteral(template);
|
|
834
|
+
}
|
|
835
|
+
else if (node.kind === 171 /* SyntaxKind.Decorator */) {
|
|
836
|
+
argCount = getDecoratorArgumentCount(c, node, signature);
|
|
837
|
+
}
|
|
838
|
+
else if (node.kind === 215 /* SyntaxKind.NewExpression */ && node.arguments === undefined) {
|
|
839
|
+
// `new C`
|
|
840
|
+
return getMinArgumentCount(c, signature) === 0;
|
|
841
|
+
}
|
|
842
|
+
else {
|
|
843
|
+
argCount = args.length;
|
|
844
|
+
// Without the close parenthesis, the call is incomplete.
|
|
845
|
+
const list = getArgumentList(node);
|
|
846
|
+
callIsIncomplete = list !== undefined && list.end === node.end;
|
|
847
|
+
// A spread argument must correspond to a rest parameter or be within range.
|
|
848
|
+
const spreadArgIndex = getSpreadArgumentIndex(args);
|
|
849
|
+
if (spreadArgIndex >= 0)
|
|
850
|
+
return (spreadArgIndex >= getMinArgumentCount(c, signature) &&
|
|
851
|
+
(hasEffectiveRestParameter(c, signature) || spreadArgIndex < getParameterCount(c, signature)));
|
|
852
|
+
}
|
|
853
|
+
if (!hasEffectiveRestParameter(c, signature) && argCount > effectiveParameterCount)
|
|
854
|
+
return false;
|
|
855
|
+
if (callIsIncomplete || argCount >= effectiveMinimumArguments)
|
|
856
|
+
return true;
|
|
857
|
+
// Missing arguments are allowed for parameters accepting `void`.
|
|
858
|
+
for (let i = argCount; i < effectiveMinimumArguments; i++) {
|
|
859
|
+
const t = getTypeAtPosition(c, signature, i);
|
|
860
|
+
if ((filterType(c, t, (u) => (u.flags & 16 /* TypeFlags.Void */) !== 0).flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
function hasCorrectTypeArgumentArity(c, signature, typeArguments) {
|
|
866
|
+
const numTypeParameters = signature.typeParameters.length;
|
|
867
|
+
const minTypeArgumentCount = getMinTypeArgumentCount(c, signature.typeParameters);
|
|
868
|
+
return (typeArguments.length === 0 ||
|
|
869
|
+
(typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters));
|
|
870
|
+
}
|
|
871
|
+
function checkTypeArguments(c, signature, typeArgumentNodes, reportErrors, headMessage) {
|
|
872
|
+
const typeParameters = signature.typeParameters;
|
|
873
|
+
const typeArguments = [];
|
|
874
|
+
for (const n of typeArgumentNodes)
|
|
875
|
+
typeArguments.push(getTypeFromTypeNode(c, n));
|
|
876
|
+
const typeArgumentTypes = fillMissingTypeArguments(c, typeArguments, typeParameters, getMinTypeArgumentCount(c, typeParameters), isInJSFile(signature.declaration));
|
|
877
|
+
const mapper = newTypeMapper(typeParameters, typeArgumentTypes);
|
|
878
|
+
for (let i = 0; i < typeArgumentNodes.length; i++) {
|
|
879
|
+
const constraint = getConstraintOfTypeParameter(c, typeParameters[i]);
|
|
880
|
+
if (constraint === undefined)
|
|
881
|
+
continue;
|
|
882
|
+
const typeArgument = typeArgumentTypes[i];
|
|
883
|
+
const diagnostics = [];
|
|
884
|
+
if (!checkTypeRelatedTo(c, typeArgument, getTypeWithThisArgument(c, instantiateType(c, constraint, mapper), typeArgument, false), c.assignableRelation, reportErrors ? typeArgumentNodes[i] : undefined, headMessage ?? 520 /* Diagnostics.Type_0_does_not_satisfy_the_constraint_1 */, diagnostics)) {
|
|
885
|
+
if (diagnostics.length !== 0)
|
|
886
|
+
c.addDiagnostic(diagnostics[0]);
|
|
887
|
+
return undefined;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return typeArgumentTypes;
|
|
891
|
+
}
|
|
892
|
+
function isSignatureApplicable(c, node, args, signature, relation, checkMode, reportErrors, diagnosticOutput) {
|
|
893
|
+
if (isJsxOpeningLikeElement(node) || node.kind === 290 /* SyntaxKind.JsxOpeningFragment */)
|
|
894
|
+
return checkApplicableSignatureForJsxCallLikeElement(c, node, signature, relation, checkMode, reportErrors, diagnosticOutput);
|
|
895
|
+
const thisType = getThisTypeOfSignature(c, signature);
|
|
896
|
+
if (thisType !== undefined &&
|
|
897
|
+
thisType !== c.voidType &&
|
|
898
|
+
!(node.kind === 215 /* SyntaxKind.NewExpression */ ||
|
|
899
|
+
(node.kind === 214 /* SyntaxKind.CallExpression */ && isSuperProperty(getExpression(node))))) {
|
|
900
|
+
// Without an `x.f` callee the `this` argument is `void`.
|
|
901
|
+
const thisArgumentNode = getThisArgumentOfCall(c, node);
|
|
902
|
+
const thisArgumentType = getThisArgumentType(c, thisArgumentNode);
|
|
903
|
+
const errorNode = reportErrors ? (thisArgumentNode ?? node) : undefined;
|
|
904
|
+
if (!checkTypeRelatedTo(c, thisArgumentType, thisType, relation, errorNode, 817 /* Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1 */, diagnosticOutput))
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
const headMessage = 521 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 */;
|
|
908
|
+
const restType = getNonArrayRestType(c, signature);
|
|
909
|
+
const argCount = restType !== undefined ? Math.min(getParameterCount(c, signature) - 1, args.length) : args.length;
|
|
910
|
+
for (let i = 0; i < argCount; i++) {
|
|
911
|
+
const arg = args[i];
|
|
912
|
+
if (arg.kind === 233 /* SyntaxKind.OmittedExpression */)
|
|
913
|
+
continue;
|
|
914
|
+
const paramType = getTypeAtPosition(c, signature, i);
|
|
915
|
+
const argType = checkArgument(c, arg, paramType, undefined, checkMode);
|
|
916
|
+
// While context-sensitive arguments are excluded, excess property checks could be false positives.
|
|
917
|
+
const checkArgType = (checkMode & 4 /* CheckMode.SkipContextSensitive */) !== 0 ? getRegularTypeOfObjectLiteral(c, argType) : argType;
|
|
918
|
+
const effectiveCheckArgumentNode = getEffectiveCheckNode(arg);
|
|
919
|
+
if (!checkTypeRelatedToAndOptionallyElaborate(c, checkArgType, paramType, relation, reportErrors ? effectiveCheckArgumentNode : undefined, effectiveCheckArgumentNode, headMessage, diagnosticOutput))
|
|
920
|
+
return false;
|
|
921
|
+
}
|
|
922
|
+
if (restType !== undefined) {
|
|
923
|
+
const spreadType = getSpreadArgumentType(c, node, args, argCount, args.length, restType, undefined, checkMode);
|
|
924
|
+
const restArgCount = args.length - argCount;
|
|
925
|
+
let errorNode = undefined;
|
|
926
|
+
if (reportErrors)
|
|
927
|
+
errorNode = restArgCount === 0 ? node : restArgCount === 1 ? getEffectiveCheckNode(args[argCount]) : node;
|
|
928
|
+
const diagnostics = [];
|
|
929
|
+
const related = checkTypeRelatedTo(c, spreadType, restType, relation, restArgCount > 1 && reportErrors ? node : errorNode, headMessage, restArgCount > 1 && reportErrors ? diagnostics : diagnosticOutput);
|
|
930
|
+
if (!related) {
|
|
931
|
+
if (restArgCount > 1 && reportErrors) {
|
|
932
|
+
// Several rest arguments: report over their combined range.
|
|
933
|
+
const file = getSourceFileOfNode(node);
|
|
934
|
+
const pos = skipTrivia(file.text, args[argCount].pos);
|
|
935
|
+
const end = args[args.length - 1].end;
|
|
936
|
+
for (const d of diagnostics) {
|
|
937
|
+
const moved = new Diagnostic(file.diagnosticFile(), pos, end, d.message, d.args.slice());
|
|
938
|
+
moved.messageChain = d.messageChain;
|
|
939
|
+
if (diagnosticOutput !== undefined)
|
|
940
|
+
diagnosticOutput.push(moved);
|
|
941
|
+
else
|
|
942
|
+
c.addDiagnostic(moved);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
function isUnterminatedLiteral(node) {
|
|
951
|
+
if (node.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */)
|
|
952
|
+
return (node.templateFlags & 4 /* TokenFlags.Unterminated */) !== 0;
|
|
953
|
+
if (node.kind === 17 /* SyntaxKind.TemplateTail */)
|
|
954
|
+
return (node.templateFlags & 4 /* TokenFlags.Unterminated */) !== 0;
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
function isSuperProperty(node) {
|
|
958
|
+
return ((node.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || node.kind === 213 /* SyntaxKind.ElementAccessExpression */) &&
|
|
959
|
+
getExpression(node).kind === 107 /* SyntaxKind.SuperKeyword */);
|
|
960
|
+
}
|
|
961
|
+
/** The `this` argument of `x.f(...)` and `x[f](...)`. */
|
|
962
|
+
function getThisArgumentOfCall(c, node) {
|
|
963
|
+
// `x instanceof C` calls `C[Symbol.hasInstance](x)`.
|
|
964
|
+
if (node.kind === 227 /* SyntaxKind.BinaryExpression */)
|
|
965
|
+
return node.right;
|
|
966
|
+
let expression = undefined;
|
|
967
|
+
if (node.kind === 214 /* SyntaxKind.CallExpression */)
|
|
968
|
+
expression = node.expression;
|
|
969
|
+
else if (node.kind === 216 /* SyntaxKind.TaggedTemplateExpression */)
|
|
970
|
+
expression = node.tag;
|
|
971
|
+
else if (node.kind === 171 /* SyntaxKind.Decorator */ && !c.legacyDecorators)
|
|
972
|
+
expression = node.expression;
|
|
973
|
+
if (expression === undefined)
|
|
974
|
+
return undefined;
|
|
975
|
+
const callee = skipOuterExpressionsForCall(expression);
|
|
976
|
+
return isAccessExpression(callee) ? getExpression(callee) : undefined;
|
|
977
|
+
}
|
|
978
|
+
function skipOuterExpressionsForCall(node) {
|
|
979
|
+
for (;;) {
|
|
980
|
+
switch (node.kind) {
|
|
981
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
982
|
+
case 235 /* SyntaxKind.AsExpression */:
|
|
983
|
+
case 217 /* SyntaxKind.TypeAssertionExpression */:
|
|
984
|
+
case 239 /* SyntaxKind.SatisfiesExpression */:
|
|
985
|
+
case 236 /* SyntaxKind.NonNullExpression */:
|
|
986
|
+
case 234 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
987
|
+
case 348 /* SyntaxKind.PartiallyEmittedExpression */:
|
|
988
|
+
node = getExpression(node);
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
return node;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
function getThisArgumentType(c, node) {
|
|
995
|
+
if (node === undefined)
|
|
996
|
+
return c.voidType;
|
|
997
|
+
const thisArgumentType = checkExpression(c, node);
|
|
998
|
+
if (isExpressionOfOptionalChainRoot(node))
|
|
999
|
+
return getNonNullableType(c, thisArgumentType);
|
|
1000
|
+
if (node.parent !== undefined && isOptionalChain(node.parent))
|
|
1001
|
+
return removeOptionalTypeMarker(c, thisArgumentType);
|
|
1002
|
+
return thisArgumentType;
|
|
1003
|
+
}
|
|
1004
|
+
// ---- Type argument inference
|
|
1005
|
+
function inferTypeArguments(c, node, signature, args, checkMode, context) {
|
|
1006
|
+
// Infer from the contextual type to the return type, e.g. from the declared type of `f` in
|
|
1007
|
+
// `let f: (x: string) => number = wrap(s => s.length)`.
|
|
1008
|
+
let skipBindingPatterns = true;
|
|
1009
|
+
for (const p of signature.typeParameters) {
|
|
1010
|
+
if (getDefaultFromTypeParameter(c, p) === undefined) {
|
|
1011
|
+
skipBindingPatterns = false;
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
// Decorators have no contextual type.
|
|
1016
|
+
const contextualType = node.kind === 171 /* SyntaxKind.Decorator */
|
|
1017
|
+
? undefined
|
|
1018
|
+
: getContextualTypeEx(c, node, skipBindingPatterns ? 8 /* ContextFlags.SkipBindingPatterns */ : 0 /* ContextFlags.None */);
|
|
1019
|
+
if (contextualType !== undefined) {
|
|
1020
|
+
const inferenceTargetType = getReturnTypeOfSignature(c, signature);
|
|
1021
|
+
if (couldContainTypeVariables(c, inferenceTargetType)) {
|
|
1022
|
+
const outerContext = getInferenceContext(c, node);
|
|
1023
|
+
const isFromBindingPattern = !skipBindingPatterns && getContextualTypeEx(c, node, 8 /* ContextFlags.SkipBindingPatterns */) !== contextualType;
|
|
1024
|
+
// A return type inference from a binding pattern only feeds `returnMapper`.
|
|
1025
|
+
if (!isFromBindingPattern) {
|
|
1026
|
+
// Snapshot what has been inferred for an outer call so far, without disturbing it.
|
|
1027
|
+
const outerMapper = getMapperFromContext(outerContext !== undefined ? cloneInferenceContext(c, outerContext, 1 /* InferenceFlags.NoDefault */) : undefined);
|
|
1028
|
+
const instantiatedType = instantiateType(c, contextualType, outerMapper);
|
|
1029
|
+
// A generic contextual signature is instantiated with its own type parameters so that they
|
|
1030
|
+
// are inferred rather than erased.
|
|
1031
|
+
const contextualSignature = getSingleCallSignature(c, instantiatedType);
|
|
1032
|
+
const inferenceSourceType = contextualSignature !== undefined && contextualSignature.typeParameters.length !== 0
|
|
1033
|
+
? getOrCreateTypeFromSignature(c, getSignatureInstantiationWithoutFillingInTypeArguments(c, contextualSignature, contextualSignature.typeParameters))
|
|
1034
|
+
: instantiatedType;
|
|
1035
|
+
// Return type inferences have the lowest priority.
|
|
1036
|
+
inferTypes(c, context.inferences, inferenceSourceType, inferenceTargetType, 128 /* InferencePriority.ReturnType */, false);
|
|
1037
|
+
}
|
|
1038
|
+
// A separate pass for the mapper used to instantiate generic contextual types, from the outer
|
|
1039
|
+
// return mapper so that inferences can't reference the type parameters being inferred.
|
|
1040
|
+
const returnContext = createInferenceContext(c, signature.typeParameters, signature, context.flags, undefined);
|
|
1041
|
+
const outerReturnMapper = outerContext !== undefined ? createOuterReturnMapper(c, outerContext) : undefined;
|
|
1042
|
+
const returnSourceType = instantiateType(c, contextualType, outerReturnMapper);
|
|
1043
|
+
inferTypes(c, returnContext.inferences, returnSourceType, inferenceTargetType, 0 /* InferencePriority.None */, false);
|
|
1044
|
+
context.returnMapper = someInferenceHasCandidates(returnContext.inferences)
|
|
1045
|
+
? getMapperFromContext(cloneInferredPartOfContext(c, returnContext))
|
|
1046
|
+
: undefined;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (isJsxOpeningLikeElement(node))
|
|
1050
|
+
return inferJsxTypeArguments(c, node, signature, checkMode, context);
|
|
1051
|
+
const restType = getNonArrayRestType(c, signature);
|
|
1052
|
+
const argCount = restType !== undefined ? Math.min(getParameterCount(c, signature) - 1, args.length) : args.length;
|
|
1053
|
+
if (restType !== undefined && (restType.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
|
|
1054
|
+
const info = context.inferences.find((i) => i.typeParameter === restType);
|
|
1055
|
+
if (info !== undefined && !hasSpreadArgumentFrom(args, argCount))
|
|
1056
|
+
info.impliedArity = args.length - argCount;
|
|
1057
|
+
}
|
|
1058
|
+
const thisType = getThisTypeOfSignature(c, signature);
|
|
1059
|
+
if (thisType !== undefined && couldContainTypeVariables(c, thisType))
|
|
1060
|
+
inferTypes(c, context.inferences, getThisArgumentType(c, getThisArgumentOfCall(c, node)), thisType, 0 /* InferencePriority.None */, false);
|
|
1061
|
+
for (let i = 0; i < argCount; i++) {
|
|
1062
|
+
const arg = args[i];
|
|
1063
|
+
if (arg.kind === 233 /* SyntaxKind.OmittedExpression */)
|
|
1064
|
+
continue;
|
|
1065
|
+
const paramType = getTypeAtPosition(c, signature, i);
|
|
1066
|
+
if (couldContainTypeVariables(c, paramType)) {
|
|
1067
|
+
const argType = checkArgument(c, arg, paramType, context, checkMode);
|
|
1068
|
+
inferTypes(c, context.inferences, argType, paramType, 0 /* InferencePriority.None */, false);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (restType !== undefined && couldContainTypeVariables(c, restType)) {
|
|
1072
|
+
const spreadType = getSpreadArgumentType(c, node, args, argCount, args.length, restType, context, checkMode);
|
|
1073
|
+
inferTypes(c, context.inferences, spreadType, restType, 0 /* InferencePriority.None */, false);
|
|
1074
|
+
}
|
|
1075
|
+
return getInferredTypes(c, context);
|
|
1076
|
+
}
|
|
1077
|
+
// ---- Overload failure
|
|
1078
|
+
/** The signature to continue with when no candidate applies; errors are already reported. */
|
|
1079
|
+
function getCandidateForOverloadFailure(c, node, candidates, args, checkMode) {
|
|
1080
|
+
checkNodeDeferred(c, node);
|
|
1081
|
+
// Overloads combine unless they're generic, which is hard to combine.
|
|
1082
|
+
if (candidates.length === 1 || candidates.some((s) => s.typeParameters.length !== 0))
|
|
1083
|
+
return pickLongestCandidateSignature(c, node, candidates, args, checkMode);
|
|
1084
|
+
return createUnionOfSignaturesForOverloadFailure(c, candidates);
|
|
1085
|
+
}
|
|
1086
|
+
function pickLongestCandidateSignature(c, node, candidates, args, checkMode) {
|
|
1087
|
+
// The longest signature gives contextual types to the most arguments.
|
|
1088
|
+
const bestIndex = getLongestCandidateIndex(c, candidates, args.length);
|
|
1089
|
+
const candidate = candidates[bestIndex];
|
|
1090
|
+
const typeParameters = candidate.typeParameters;
|
|
1091
|
+
if (typeParameters.length === 0)
|
|
1092
|
+
return candidate;
|
|
1093
|
+
const typeArgumentNodes = getCallTypeArguments(node);
|
|
1094
|
+
let instantiated;
|
|
1095
|
+
if (typeArgumentNodes.length !== 0)
|
|
1096
|
+
instantiated = createSignatureInstantiation(c, candidate, getTypeArgumentsFromNodes(c, typeArgumentNodes, typeParameters));
|
|
1097
|
+
else {
|
|
1098
|
+
const inferenceContext = createInferenceContext(c, typeParameters, candidate, isInJSFile(node) ? 2 /* InferenceFlags.AnyDefault */ : 0 /* InferenceFlags.None */, undefined);
|
|
1099
|
+
const typeArgumentTypes = inferTypeArguments(c, node, candidate, args, checkMode | 4 /* CheckMode.SkipContextSensitive */ | 8 /* CheckMode.SkipGenericFunctions */, inferenceContext);
|
|
1100
|
+
instantiated = createSignatureInstantiation(c, candidate, typeArgumentTypes);
|
|
1101
|
+
}
|
|
1102
|
+
candidates[bestIndex] = instantiated;
|
|
1103
|
+
return instantiated;
|
|
1104
|
+
}
|
|
1105
|
+
function getLongestCandidateIndex(c, candidates, argsCount) {
|
|
1106
|
+
let maxParamsIndex = -1;
|
|
1107
|
+
let maxParams = -1;
|
|
1108
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
1109
|
+
const candidate = candidates[i];
|
|
1110
|
+
const paramCount = getParameterCount(c, candidate);
|
|
1111
|
+
if (hasEffectiveRestParameter(c, candidate) || paramCount >= argsCount)
|
|
1112
|
+
return i;
|
|
1113
|
+
if (paramCount > maxParams) {
|
|
1114
|
+
maxParams = paramCount;
|
|
1115
|
+
maxParamsIndex = i;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return maxParamsIndex;
|
|
1119
|
+
}
|
|
1120
|
+
function hasSpreadArgumentFrom(args, start) {
|
|
1121
|
+
for (let i = start; i < args.length; i++)
|
|
1122
|
+
if (isSpreadArgument(args[i]))
|
|
1123
|
+
return true;
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
function getTypeArgumentsFromNodes(c, typeArgumentNodes, typeParameters) {
|
|
1127
|
+
const typeArguments = [];
|
|
1128
|
+
for (const n of typeArgumentNodes) {
|
|
1129
|
+
if (typeArguments.length === typeParameters.length)
|
|
1130
|
+
break;
|
|
1131
|
+
typeArguments.push(getTypeFromTypeNode(c, n));
|
|
1132
|
+
}
|
|
1133
|
+
while (typeArguments.length < typeParameters.length) {
|
|
1134
|
+
const tp = typeParameters[typeArguments.length];
|
|
1135
|
+
typeArguments.push(getDefaultFromTypeParameter(c, tp) ?? getConstraintOfTypeParameter(c, tp) ?? c.unknownType);
|
|
1136
|
+
}
|
|
1137
|
+
return typeArguments;
|
|
1138
|
+
}
|
|
1139
|
+
function createUnionOfSignaturesForOverloadFailure(c, candidates) {
|
|
1140
|
+
const thisParameters = [];
|
|
1141
|
+
const thisTypes = [];
|
|
1142
|
+
for (const s of candidates) {
|
|
1143
|
+
if (s.thisParameter !== undefined) {
|
|
1144
|
+
thisParameters.push(s.thisParameter);
|
|
1145
|
+
thisTypes.push(getTypeOfParameter(c, s.thisParameter));
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
const thisParameter = thisParameters.length !== 0 ? createCombinedSymbolFromTypes(c, thisParameters, thisTypes) : undefined;
|
|
1149
|
+
let minArgumentCount = Number.MAX_SAFE_INTEGER;
|
|
1150
|
+
let maxNonRestParam = 0;
|
|
1151
|
+
for (const s of candidates) {
|
|
1152
|
+
const count = s.hasRestParameter() ? s.parameters.length - 1 : s.parameters.length;
|
|
1153
|
+
minArgumentCount = Math.min(minArgumentCount, count);
|
|
1154
|
+
maxNonRestParam = Math.max(maxNonRestParam, count);
|
|
1155
|
+
}
|
|
1156
|
+
const parameters = [];
|
|
1157
|
+
for (let i = 0; i < maxNonRestParam; i++) {
|
|
1158
|
+
const symbols = [];
|
|
1159
|
+
const types = [];
|
|
1160
|
+
for (const s of candidates) {
|
|
1161
|
+
const p = s.hasRestParameter()
|
|
1162
|
+
? i < s.parameters.length - 1
|
|
1163
|
+
? s.parameters[i]
|
|
1164
|
+
: s.parameters[s.parameters.length - 1]
|
|
1165
|
+
: i < s.parameters.length
|
|
1166
|
+
? s.parameters[i]
|
|
1167
|
+
: undefined;
|
|
1168
|
+
if (p !== undefined)
|
|
1169
|
+
symbols.push(p);
|
|
1170
|
+
const t = tryGetTypeAtPosition(c, s, i);
|
|
1171
|
+
if (t !== undefined)
|
|
1172
|
+
types.push(t);
|
|
1173
|
+
}
|
|
1174
|
+
parameters.push(createCombinedSymbolFromTypes(c, symbols, types));
|
|
1175
|
+
}
|
|
1176
|
+
const restParameterSymbols = [];
|
|
1177
|
+
const restTypes = [];
|
|
1178
|
+
for (const s of candidates)
|
|
1179
|
+
if (s.hasRestParameter()) {
|
|
1180
|
+
restParameterSymbols.push(s.parameters[s.parameters.length - 1]);
|
|
1181
|
+
const t = tryGetRestTypeOfSignature(c, s);
|
|
1182
|
+
if (t !== undefined)
|
|
1183
|
+
restTypes.push(t);
|
|
1184
|
+
}
|
|
1185
|
+
let flags = 256 /* SignatureFlags.IsSignatureCandidateForOverloadFailure */;
|
|
1186
|
+
if (restParameterSymbols.length !== 0) {
|
|
1187
|
+
const t = createArrayType(c, getUnionTypeEx(c, restTypes, 2 /* UnionReduction.Subtype */, undefined, undefined));
|
|
1188
|
+
parameters.push(createSymbolWithType(c, restParameterSymbols[0], t));
|
|
1189
|
+
flags |= 1 /* SignatureFlags.HasRestParameter */;
|
|
1190
|
+
}
|
|
1191
|
+
if (candidates.some((s) => (s.flags & 2 /* SignatureFlags.HasLiteralTypes */) !== 0))
|
|
1192
|
+
flags |= 2 /* SignatureFlags.HasLiteralTypes */;
|
|
1193
|
+
const returnTypes = [];
|
|
1194
|
+
for (const s of candidates)
|
|
1195
|
+
returnTypes.push(getReturnTypeOfSignature(c, s));
|
|
1196
|
+
return c.newSignature(flags, candidates[0].declaration, [], thisParameter, parameters, getIntersectionType(c, returnTypes), minArgumentCount);
|
|
1197
|
+
}
|
|
1198
|
+
function createCombinedSymbolFromTypes(c, sources, types) {
|
|
1199
|
+
return createSymbolWithType(c, sources[0], getUnionTypeEx(c, types, 2 /* UnionReduction.Subtype */, undefined, undefined));
|
|
1200
|
+
}
|
|
1201
|
+
export function tryGetRestTypeOfSignature(c, signature) {
|
|
1202
|
+
if (!signature.hasRestParameter())
|
|
1203
|
+
return undefined;
|
|
1204
|
+
let restType = getTypeOfSymbol(c, signature.parameters[signature.parameters.length - 1]);
|
|
1205
|
+
if (isTupleType(restType)) {
|
|
1206
|
+
restType = getRestTypeOfTupleType(c, restType);
|
|
1207
|
+
if (restType === undefined)
|
|
1208
|
+
return undefined;
|
|
1209
|
+
}
|
|
1210
|
+
return getIndexTypeOfType(c, restType, c.numberType);
|
|
1211
|
+
}
|
|
1212
|
+
// ---- Resolution errors
|
|
1213
|
+
function reportCallResolutionErrors(c, s, signatures, headMessage) {
|
|
1214
|
+
if (s.candidatesForArgumentError.length !== 0) {
|
|
1215
|
+
const last = s.candidatesForArgumentError[s.candidatesForArgumentError.length - 1];
|
|
1216
|
+
const diagnostics = [];
|
|
1217
|
+
isSignatureApplicable(c, s.node, s.args, last, c.assignableRelation, 0 /* CheckMode.Normal */, true, diagnostics);
|
|
1218
|
+
for (let diagnostic of diagnostics) {
|
|
1219
|
+
if (s.candidatesForArgumentError.length > 1) {
|
|
1220
|
+
diagnostic = chainDiagnostic(diagnostic, 902 /* Diagnostics.The_last_overload_gave_the_following_error */);
|
|
1221
|
+
diagnostic = chainDiagnostic(diagnostic, 901 /* Diagnostics.No_overload_matches_this_call */);
|
|
1222
|
+
}
|
|
1223
|
+
if (headMessage !== undefined)
|
|
1224
|
+
diagnostic = chainDiagnostic(diagnostic, headMessage);
|
|
1225
|
+
if (last.declaration !== undefined && s.candidatesForArgumentError.length > 1)
|
|
1226
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(last.declaration, 903 /* Diagnostics.The_last_overload_is_declared_here */, []));
|
|
1227
|
+
addImplementationSuccessElaboration(c, s, last, diagnostic);
|
|
1228
|
+
c.addDiagnostic(diagnostic);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
else if (s.candidateForArgumentArityError !== undefined)
|
|
1232
|
+
c.addDiagnostic(getArgumentArityError(c, s.node, [s.candidateForArgumentArityError], s.args, headMessage));
|
|
1233
|
+
else if (s.candidateForTypeArgumentError !== undefined)
|
|
1234
|
+
checkTypeArguments(c, s.candidateForTypeArgumentError, getCallTypeArguments(s.node), true, headMessage);
|
|
1235
|
+
else if (s.node.kind !== 290 /* SyntaxKind.JsxOpeningFragment */) {
|
|
1236
|
+
const withCorrectTypeArgumentArity = [];
|
|
1237
|
+
for (const sig of signatures)
|
|
1238
|
+
if (hasCorrectTypeArgumentArity(c, sig, s.typeArguments))
|
|
1239
|
+
withCorrectTypeArgumentArity.push(sig);
|
|
1240
|
+
if (withCorrectTypeArgumentArity.length === 0)
|
|
1241
|
+
c.addDiagnostic(getTypeArgumentArityError(c, s.node, signatures, s.typeArguments, headMessage));
|
|
1242
|
+
else
|
|
1243
|
+
c.addDiagnostic(getArgumentArityError(c, s.node, withCorrectTypeArgumentArity, s.args, headMessage));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
/** Notes when the call would have resolved to the implementation signature of the overloads. */
|
|
1247
|
+
function addImplementationSuccessElaboration(c, s, failed, diagnostic) {
|
|
1248
|
+
const symbol = failed.declaration !== undefined ? getSymbol(failed.declaration) : undefined;
|
|
1249
|
+
if (symbol === undefined || symbol.declarations.length <= 1)
|
|
1250
|
+
return;
|
|
1251
|
+
let implementation;
|
|
1252
|
+
for (const d of symbol.declarations) {
|
|
1253
|
+
if (isFunctionLikeDeclarationKind(d.kind) && nodeIsPresent(getBody(d))) {
|
|
1254
|
+
implementation = d;
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (implementation === undefined)
|
|
1259
|
+
return;
|
|
1260
|
+
const candidate = getSignatureFromDeclaration(c, implementation);
|
|
1261
|
+
const localState = new CallState(s.node, s.typeArguments, s.args, [candidate]);
|
|
1262
|
+
localState.argCheckMode = s.argCheckMode;
|
|
1263
|
+
localState.isSingleNonGenericCandidate = candidate.typeParameters.length === 0;
|
|
1264
|
+
localState.candidatesForArgumentError = s.candidatesForArgumentError.slice();
|
|
1265
|
+
localState.candidateForArgumentArityError = s.candidateForArgumentArityError;
|
|
1266
|
+
localState.candidateForTypeArgumentError = s.candidateForTypeArgumentError;
|
|
1267
|
+
if (chooseOverload(c, localState, c.assignableRelation) !== undefined)
|
|
1268
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(implementation, 925 /* Diagnostics.The_call_would_have_succeeded_against_this_implementation_but_implementation_signatures_of_overloads_are_not_externally_visible */, []));
|
|
1269
|
+
}
|
|
1270
|
+
function withHeadMessage(diagnostic, headMessage) {
|
|
1271
|
+
return headMessage !== undefined ? chainDiagnostic(diagnostic, headMessage) : diagnostic;
|
|
1272
|
+
}
|
|
1273
|
+
function getArgumentArityError(c, node, signatures, args, headMessage) {
|
|
1274
|
+
const spreadIndex = getSpreadArgumentIndex(args);
|
|
1275
|
+
if (spreadIndex > -1)
|
|
1276
|
+
return createDiagnosticForNode(args[spreadIndex], 711 /* Diagnostics.A_spread_argument_must_either_have_a_tuple_type_or_be_passed_to_a_rest_parameter */, []);
|
|
1277
|
+
let minCount = Number.MAX_SAFE_INTEGER;
|
|
1278
|
+
let maxCount = Number.MIN_SAFE_INTEGER;
|
|
1279
|
+
let maxBelow = Number.MIN_SAFE_INTEGER;
|
|
1280
|
+
let minAbove = Number.MAX_SAFE_INTEGER;
|
|
1281
|
+
let closestSignature = undefined;
|
|
1282
|
+
for (const sig of signatures) {
|
|
1283
|
+
const minParameter = getMinArgumentCount(c, sig);
|
|
1284
|
+
const maxParameter = getParameterCount(c, sig);
|
|
1285
|
+
if (minParameter < minCount) {
|
|
1286
|
+
minCount = minParameter;
|
|
1287
|
+
closestSignature = sig;
|
|
1288
|
+
}
|
|
1289
|
+
maxCount = Math.max(maxCount, maxParameter);
|
|
1290
|
+
if (minParameter < args.length && minParameter > maxBelow)
|
|
1291
|
+
maxBelow = minParameter;
|
|
1292
|
+
if (args.length < maxParameter && maxParameter < minAbove)
|
|
1293
|
+
minAbove = maxParameter;
|
|
1294
|
+
}
|
|
1295
|
+
let hasRestParameter = false;
|
|
1296
|
+
for (const sig of signatures) {
|
|
1297
|
+
if (hasEffectiveRestParameter(c, sig)) {
|
|
1298
|
+
hasRestParameter = true;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
const parameterRange = hasRestParameter
|
|
1303
|
+
? String(minCount)
|
|
1304
|
+
: minCount < maxCount
|
|
1305
|
+
? minCount + '-' + maxCount
|
|
1306
|
+
: String(minCount);
|
|
1307
|
+
const errorNode = getErrorNodeForCallNode(node);
|
|
1308
|
+
const message = node.kind === 171 /* SyntaxKind.Decorator */
|
|
1309
|
+
? hasRestParameter
|
|
1310
|
+
? 228 /* Diagnostics.The_runtime_will_invoke_the_decorator_with_1_arguments_but_the_decorator_expects_at_least_0 */
|
|
1311
|
+
: 227 /* Diagnostics.The_runtime_will_invoke_the_decorator_with_1_arguments_but_the_decorator_expects_0 */
|
|
1312
|
+
: hasRestParameter
|
|
1313
|
+
? 710 /* Diagnostics.Expected_at_least_0_arguments_but_got_1 */
|
|
1314
|
+
: 709 /* Diagnostics.Expected_0_arguments_but_got_1 */;
|
|
1315
|
+
if (minCount < args.length && args.length < maxCount)
|
|
1316
|
+
// Between min and max, but no overload matches.
|
|
1317
|
+
return withHeadMessage(createDiagnosticForNode(errorNode, 726 /* Diagnostics.No_overload_expects_0_arguments_but_overloads_do_exist_that_expect_either_1_or_2_arguments */, [String(args.length), String(maxBelow), String(minAbove)]), headMessage);
|
|
1318
|
+
if (args.length < minCount) {
|
|
1319
|
+
// Too short: the error spans the callee.
|
|
1320
|
+
const diagnostic = withHeadMessage(createDiagnosticForNode(errorNode, message, [parameterRange, String(args.length)]), headMessage);
|
|
1321
|
+
const declaration = closestSignature !== undefined ? closestSignature.declaration : undefined;
|
|
1322
|
+
const params = declaration !== undefined ? getParameters(declaration) : undefined;
|
|
1323
|
+
const index = args.length + (closestSignature.thisParameter !== undefined ? 1 : 0);
|
|
1324
|
+
const parameter = params !== undefined && index < params.nodes.length ? params.nodes[index] : undefined;
|
|
1325
|
+
if (parameter !== undefined) {
|
|
1326
|
+
const name = getName(parameter);
|
|
1327
|
+
if (name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)
|
|
1328
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(parameter, 1364 /* Diagnostics.An_argument_matching_this_binding_pattern_was_not_provided */, []));
|
|
1329
|
+
else if (parameter.dotDotDotToken !== undefined)
|
|
1330
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(parameter, 1388 /* Diagnostics.Arguments_for_the_rest_parameter_0_were_not_provided */, [
|
|
1331
|
+
getTextOfName(name),
|
|
1332
|
+
]));
|
|
1333
|
+
else
|
|
1334
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(parameter, 1363 /* Diagnostics.An_argument_for_0_was_not_provided */, [getTextOfName(name)]));
|
|
1335
|
+
}
|
|
1336
|
+
return diagnostic;
|
|
1337
|
+
}
|
|
1338
|
+
if (maxCount >= args.length)
|
|
1339
|
+
return withHeadMessage(createDiagnosticForNode(errorNode, message, [parameterRange, String(args.length)]), headMessage);
|
|
1340
|
+
// Too long: the error spans the excess arguments.
|
|
1341
|
+
const file = getSourceFileOfNode(node);
|
|
1342
|
+
let pos = args[maxCount].pos;
|
|
1343
|
+
let end = args[args.length - 1].end;
|
|
1344
|
+
if (end === pos)
|
|
1345
|
+
end++;
|
|
1346
|
+
pos = skipTrivia(file.text, pos);
|
|
1347
|
+
if (end < pos)
|
|
1348
|
+
end = pos;
|
|
1349
|
+
return withHeadMessage(new Diagnostic(file.diagnosticFile(), pos, end, message, [parameterRange, String(args.length)]), headMessage);
|
|
1350
|
+
}
|
|
1351
|
+
function getTypeArgumentArityError(c, node, signatures, typeArguments, headMessage) {
|
|
1352
|
+
const argCount = typeArguments.length;
|
|
1353
|
+
const file = getSourceFileOfNode(node);
|
|
1354
|
+
const list = getTypeArgumentList(node);
|
|
1355
|
+
const pos = skipTrivia(file.text, list.pos);
|
|
1356
|
+
const end = list.end;
|
|
1357
|
+
let diagnostic;
|
|
1358
|
+
if (signatures.length === 1) {
|
|
1359
|
+
// No overloads.
|
|
1360
|
+
const sig = signatures[0];
|
|
1361
|
+
const minCount = getMinTypeArgumentCount(c, sig.typeParameters);
|
|
1362
|
+
const maxCount = sig.typeParameters.length;
|
|
1363
|
+
const expected = minCount < maxCount ? minCount + '-' + maxCount : String(minCount);
|
|
1364
|
+
diagnostic = new Diagnostic(file.diagnosticFile(), pos, end, 712 /* Diagnostics.Expected_0_type_arguments_but_got_1 */, [
|
|
1365
|
+
expected,
|
|
1366
|
+
String(argCount),
|
|
1367
|
+
]);
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
let belowArgCount = Number.MIN_SAFE_INTEGER;
|
|
1371
|
+
let aboveArgCount = Number.MAX_SAFE_INTEGER;
|
|
1372
|
+
for (const sig of signatures) {
|
|
1373
|
+
const minCount = getMinTypeArgumentCount(c, sig.typeParameters);
|
|
1374
|
+
const maxCount = sig.typeParameters.length;
|
|
1375
|
+
if (minCount > argCount)
|
|
1376
|
+
aboveArgCount = Math.min(aboveArgCount, minCount);
|
|
1377
|
+
else if (maxCount < argCount)
|
|
1378
|
+
belowArgCount = Math.max(belowArgCount, maxCount);
|
|
1379
|
+
}
|
|
1380
|
+
diagnostic =
|
|
1381
|
+
belowArgCount !== Number.MIN_SAFE_INTEGER && aboveArgCount !== Number.MAX_SAFE_INTEGER
|
|
1382
|
+
? new Diagnostic(file.diagnosticFile(), pos, end, 875 /* Diagnostics.No_overload_expects_0_type_arguments_but_overloads_do_exist_that_expect_either_1_or_2_type_arguments */, [String(argCount), String(belowArgCount), String(aboveArgCount)])
|
|
1383
|
+
: new Diagnostic(file.diagnosticFile(), pos, end, 712 /* Diagnostics.Expected_0_type_arguments_but_got_1 */, [
|
|
1384
|
+
String(belowArgCount === Number.MIN_SAFE_INTEGER ? aboveArgCount : belowArgCount),
|
|
1385
|
+
String(argCount),
|
|
1386
|
+
]);
|
|
1387
|
+
}
|
|
1388
|
+
return withHeadMessage(diagnostic, headMessage);
|
|
1389
|
+
}
|
|
1390
|
+
function getTextOfName(name) {
|
|
1391
|
+
return name.kind === 79 /* SyntaxKind.Identifier */ ? getText(name) : '';
|
|
1392
|
+
}
|
|
1393
|
+
function getErrorNodeForCallNode(node) {
|
|
1394
|
+
if (node.kind === 214 /* SyntaxKind.CallExpression */) {
|
|
1395
|
+
const callee = node.expression;
|
|
1396
|
+
if (callee.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
|
|
1397
|
+
return getName(callee);
|
|
1398
|
+
return callee;
|
|
1399
|
+
}
|
|
1400
|
+
return node;
|
|
1401
|
+
}
|
|
1402
|
+
// ---- Generic function arguments
|
|
1403
|
+
/**
|
|
1404
|
+
* Under inferential typing, a generic function argument whose contextual type is a non-generic
|
|
1405
|
+
* function is instantiated in the context of that function type.
|
|
1406
|
+
*/
|
|
1407
|
+
export function instantiateTypeWithSingleGenericCallSignature(c, node, t, checkMode) {
|
|
1408
|
+
if ((checkMode & (2 /* CheckMode.Inferential */ | 8 /* CheckMode.SkipGenericFunctions */)) === 0)
|
|
1409
|
+
return t;
|
|
1410
|
+
const callSignature = getSingleSignature(c, t, 0 /* SignatureKind.Call */, true);
|
|
1411
|
+
const constructSignature = getSingleSignature(c, t, 1 /* SignatureKind.Construct */, true);
|
|
1412
|
+
const signature = callSignature ?? constructSignature;
|
|
1413
|
+
if (signature === undefined || signature.typeParameters.length === 0)
|
|
1414
|
+
return t;
|
|
1415
|
+
const contextualType = getApparentTypeOfContextualTypeEx(c, node, 2 /* ContextFlags.NoConstraints */);
|
|
1416
|
+
if (contextualType === undefined)
|
|
1417
|
+
return t;
|
|
1418
|
+
const contextualSignature = getSingleSignature(c, getNonNullableType(c, contextualType), callSignature !== undefined ? 0 /* SignatureKind.Call */ : 1 /* SignatureKind.Construct */, false);
|
|
1419
|
+
if (contextualSignature === undefined || contextualSignature.typeParameters.length !== 0)
|
|
1420
|
+
return t;
|
|
1421
|
+
if ((checkMode & 8 /* CheckMode.SkipGenericFunctions */) !== 0) {
|
|
1422
|
+
skippedGenericFunction(c, node, checkMode);
|
|
1423
|
+
return c.anyFunctionType;
|
|
1424
|
+
}
|
|
1425
|
+
const context = getInferenceContext(c, node);
|
|
1426
|
+
// When the outer function returns a non-generic function and some of its type parameters have no
|
|
1427
|
+
// inferences yet, the argument's type parameters may become type parameters of that result.
|
|
1428
|
+
const returnType = context.signature !== undefined ? getReturnTypeOfSignature(c, context.signature) : undefined;
|
|
1429
|
+
const returnSignature = returnType !== undefined ? getSingleCallOrConstructSignature(c, returnType) : undefined;
|
|
1430
|
+
if (returnSignature !== undefined &&
|
|
1431
|
+
returnSignature.typeParameters.length === 0 &&
|
|
1432
|
+
!everyInferenceHasCandidates(context.inferences)) {
|
|
1433
|
+
// Instantiate with its own type parameters, renamed to be unique where needed.
|
|
1434
|
+
const uniqueTypeParameters = getUniqueTypeParameters(c, context, signature.typeParameters);
|
|
1435
|
+
const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(c, signature, uniqueTypeParameters);
|
|
1436
|
+
// Infer from its parameters to the contextual signature's, from no candidates.
|
|
1437
|
+
const inferences = context.inferences.map((info) => new InferenceInfo(info.typeParameter));
|
|
1438
|
+
applyToParameterTypes(c, instantiatedSignature, contextualSignature, (source, target) => inferTypes(c, inferences, source, target, 0 /* InferencePriority.None */, true));
|
|
1439
|
+
if (someInferenceHasCandidates(inferences)) {
|
|
1440
|
+
// Type parameters are referenced by the contextual parameters; also infer from the return type.
|
|
1441
|
+
applyToReturnTypes(c, instantiatedSignature, contextualSignature, (source, target) => inferTypes(c, inferences, source, target, 0 /* InferencePriority.None */, false));
|
|
1442
|
+
// Without overlapping inferences, adopt the new candidates and the argument's type parameters.
|
|
1443
|
+
if (!hasOverlappingInferences(context.inferences, inferences)) {
|
|
1444
|
+
mergeInferences(context.inferences, inferences);
|
|
1445
|
+
context.inferredTypeParameters =
|
|
1446
|
+
context.inferredTypeParameters !== undefined
|
|
1447
|
+
? context.inferredTypeParameters.concat(uniqueTypeParameters)
|
|
1448
|
+
: uniqueTypeParameters;
|
|
1449
|
+
return getOrCreateTypeFromSignature(c, instantiatedSignature);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return getOrCreateTypeFromSignature(c, instantiateSignatureInContextOf(c, signature, contextualSignature, context, undefined));
|
|
1454
|
+
}
|
|
1455
|
+
function getUniqueTypeParameters(c, context, typeParameters) {
|
|
1456
|
+
const oldTypeParameters = [];
|
|
1457
|
+
const newTypeParameters = [];
|
|
1458
|
+
const result = [];
|
|
1459
|
+
const inferred = context.inferredTypeParameters ?? [];
|
|
1460
|
+
for (const tp of typeParameters) {
|
|
1461
|
+
const name = tp.symbol.name;
|
|
1462
|
+
if (hasTypeParameterByName(inferred, name) || hasTypeParameterByName(result, name)) {
|
|
1463
|
+
const newName = getUniqueTypeParameterName(inferred.concat(result), name);
|
|
1464
|
+
const newTypeParameter = c.newTypeParameter(c.newSymbol(262144 /* SymbolFlags.TypeParameter */, newName));
|
|
1465
|
+
newTypeParameter.target = tp;
|
|
1466
|
+
oldTypeParameters.push(tp);
|
|
1467
|
+
newTypeParameters.push(newTypeParameter);
|
|
1468
|
+
result.push(newTypeParameter);
|
|
1469
|
+
}
|
|
1470
|
+
else
|
|
1471
|
+
result.push(tp);
|
|
1472
|
+
}
|
|
1473
|
+
if (newTypeParameters.length !== 0) {
|
|
1474
|
+
const mapper = newTypeMapper(oldTypeParameters, newTypeParameters);
|
|
1475
|
+
for (const tp of newTypeParameters)
|
|
1476
|
+
tp.mapper = mapper;
|
|
1477
|
+
}
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
function hasTypeParameterByName(typeParameters, name) {
|
|
1481
|
+
return typeParameters.some((tp) => tp.symbol.name === name);
|
|
1482
|
+
}
|
|
1483
|
+
function getUniqueTypeParameterName(typeParameters, baseName) {
|
|
1484
|
+
while (baseName.length > 1 &&
|
|
1485
|
+
baseName.charCodeAt(baseName.length - 1) >= 0x30 &&
|
|
1486
|
+
baseName.charCodeAt(baseName.length - 1) <= 0x39)
|
|
1487
|
+
baseName = baseName.substring(0, baseName.length - 1);
|
|
1488
|
+
for (let index = 1;; index++) {
|
|
1489
|
+
const augmentedName = baseName + index;
|
|
1490
|
+
if (!hasTypeParameterByName(typeParameters, augmentedName))
|
|
1491
|
+
return augmentedName;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
/** A signature instantiation whose function return type takes the inferred type parameters. */
|
|
1495
|
+
function getSignatureInstantiationWithInferredTypeParameters(c, sig, typeArguments, isJavaScript, inferredTypeParameters) {
|
|
1496
|
+
const instantiatedSignature = getSignatureInstantiation(c, sig, typeArguments, isJavaScript);
|
|
1497
|
+
if (inferredTypeParameters === undefined || inferredTypeParameters.length === 0)
|
|
1498
|
+
return instantiatedSignature;
|
|
1499
|
+
const returnSignature = getSingleCallOrConstructSignature(c, getReturnTypeOfSignature(c, instantiatedSignature));
|
|
1500
|
+
if (returnSignature === undefined)
|
|
1501
|
+
return instantiatedSignature;
|
|
1502
|
+
const newReturnSignature = cloneSignature(c, returnSignature);
|
|
1503
|
+
newReturnSignature.typeParameters = inferredTypeParameters;
|
|
1504
|
+
const newReturnType = getOrCreateTypeFromSignature(c, newReturnSignature);
|
|
1505
|
+
newReturnType.mapper = instantiatedSignature.mapper;
|
|
1506
|
+
const newInstantiatedSignature = cloneSignature(c, instantiatedSignature);
|
|
1507
|
+
newInstantiatedSignature.resolvedReturnType = newReturnType;
|
|
1508
|
+
return newInstantiatedSignature;
|
|
1509
|
+
}
|
|
1510
|
+
// ---- Instantiation expressions
|
|
1511
|
+
/** Checks `f<T>` in an expression, or `typeof f<T>`. */
|
|
1512
|
+
export function checkExpressionWithTypeArguments(c, node) {
|
|
1513
|
+
const typeArguments = getTypeArgumentList(node);
|
|
1514
|
+
if (typeArguments !== undefined)
|
|
1515
|
+
for (const a of typeArguments.nodes)
|
|
1516
|
+
checkSourceElement(c, a);
|
|
1517
|
+
let exprType;
|
|
1518
|
+
if (node.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */) {
|
|
1519
|
+
let parent = node.parent;
|
|
1520
|
+
while (parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
|
|
1521
|
+
parent = parent.parent;
|
|
1522
|
+
if (parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
|
|
1523
|
+
parent.operatorToken.kind === 103 /* SyntaxKind.InstanceOfKeyword */ &&
|
|
1524
|
+
isNodeDescendantOf(node, parent.right))
|
|
1525
|
+
c.error(node, 968 /* Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_not_be_an_instantiation_expression */);
|
|
1526
|
+
exprType = checkExpression(c, getExpression(node));
|
|
1527
|
+
}
|
|
1528
|
+
else
|
|
1529
|
+
exprType = checkTypeQueryExpression(c, node);
|
|
1530
|
+
return getInstantiationExpressionType(c, exprType, node);
|
|
1531
|
+
}
|
|
1532
|
+
/** The type of an expression with type arguments: its generic signatures instantiated with them. */
|
|
1533
|
+
export function getInstantiationExpressionType(c, exprType, node) {
|
|
1534
|
+
const typeArgumentList = getTypeArgumentList(node);
|
|
1535
|
+
if (exprType === c.silentNeverType || isErrorType(c, exprType) || typeArgumentList === undefined)
|
|
1536
|
+
return exprType;
|
|
1537
|
+
const key = `${getNodeId(node)},${exprType.id}`;
|
|
1538
|
+
const cached = c.instantiationExpressionTypes.get(key);
|
|
1539
|
+
if (cached !== undefined)
|
|
1540
|
+
return cached;
|
|
1541
|
+
const instantiator = new InstantiationExpressionInstantiator(c, node, typeArgumentList.nodes);
|
|
1542
|
+
const result = instantiator.instantiateType(exprType);
|
|
1543
|
+
c.instantiationExpressionTypes.set(key, result);
|
|
1544
|
+
const errorType = instantiator.hasSomeApplicableSignature ? instantiator.nonApplicableType : exprType;
|
|
1545
|
+
if (errorType !== undefined) {
|
|
1546
|
+
const file = getSourceFileOfNode(node);
|
|
1547
|
+
c.addDiagnostic(new Diagnostic(file.diagnosticFile(), skipTrivia(file.text, typeArgumentList.pos), typeArgumentList.end, 778 /* Diagnostics.Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable */, [typeToString(c, errorType)]));
|
|
1548
|
+
}
|
|
1549
|
+
return result;
|
|
1550
|
+
}
|
|
1551
|
+
/** Instantiates the generic signatures of a type and its constituents with explicit type arguments. */
|
|
1552
|
+
class InstantiationExpressionInstantiator {
|
|
1553
|
+
c;
|
|
1554
|
+
node;
|
|
1555
|
+
typeArguments;
|
|
1556
|
+
hasSomeApplicableSignature = false;
|
|
1557
|
+
nonApplicableType = undefined;
|
|
1558
|
+
hasSignatures = false;
|
|
1559
|
+
hasApplicableSignature = false;
|
|
1560
|
+
constructor(c, node, typeArguments) {
|
|
1561
|
+
this.c = c;
|
|
1562
|
+
this.node = node;
|
|
1563
|
+
this.typeArguments = typeArguments;
|
|
1564
|
+
}
|
|
1565
|
+
instantiateType(t) {
|
|
1566
|
+
const saveHasSignatures = this.hasSignatures;
|
|
1567
|
+
const saveHasApplicableSignature = this.hasApplicableSignature;
|
|
1568
|
+
this.hasSignatures = false;
|
|
1569
|
+
this.hasApplicableSignature = false;
|
|
1570
|
+
const result = this.instantiateTypePart(t);
|
|
1571
|
+
if (this.hasApplicableSignature)
|
|
1572
|
+
this.hasSomeApplicableSignature = true;
|
|
1573
|
+
if (this.hasSignatures && !this.hasApplicableSignature && this.nonApplicableType === undefined)
|
|
1574
|
+
this.nonApplicableType = t;
|
|
1575
|
+
this.hasSignatures = saveHasSignatures;
|
|
1576
|
+
this.hasApplicableSignature = saveHasApplicableSignature;
|
|
1577
|
+
return result;
|
|
1578
|
+
}
|
|
1579
|
+
instantiateTypePart(t) {
|
|
1580
|
+
const c = this.c;
|
|
1581
|
+
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
1582
|
+
const resolved = resolveStructuredTypeMembers(c, t);
|
|
1583
|
+
const callSignatures = this.instantiateSignatures(resolved.callSignatures);
|
|
1584
|
+
const constructSignatures = this.instantiateSignatures(resolved.constructSignatures);
|
|
1585
|
+
if (resolved.callSignatures.length !== 0 || resolved.constructSignatures.length !== 0)
|
|
1586
|
+
this.hasSignatures = true;
|
|
1587
|
+
if (callSignatures.length !== 0 || constructSignatures.length !== 0)
|
|
1588
|
+
this.hasApplicableSignature = true;
|
|
1589
|
+
if (callSignatures !== resolved.callSignatures || constructSignatures !== resolved.constructSignatures) {
|
|
1590
|
+
const result = newObjectType(c, 16 /* ObjectFlags.Anonymous */ | 16777216 /* ObjectFlags.InstantiationExpressionType */, c.newSymbol(0 /* SymbolFlags.None */, "\uFFFEinstantiationExpression" /* InternalSymbolName.InstantiationExpression */));
|
|
1591
|
+
setStructuredTypeMembers(c, result, resolved.members, callSignatures, constructSignatures, resolved.indexInfos);
|
|
1592
|
+
result.node = this.node;
|
|
1593
|
+
return result;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
else if ((t.flags & 117964800 /* TypeFlags.InstantiableNonPrimitive */) !== 0) {
|
|
1597
|
+
const constraint = getBaseConstraintOfType(c, t);
|
|
1598
|
+
if (constraint !== undefined) {
|
|
1599
|
+
const instantiated = this.instantiateTypePart(constraint);
|
|
1600
|
+
if (instantiated !== constraint)
|
|
1601
|
+
return instantiated;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
else if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
1605
|
+
return mapType(c, t, (u) => this.instantiateType(u));
|
|
1606
|
+
else if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
1607
|
+
const types = typesOf(t);
|
|
1608
|
+
const instantiated = [];
|
|
1609
|
+
let changed = false;
|
|
1610
|
+
for (const u of types) {
|
|
1611
|
+
const v = this.instantiateTypePart(u);
|
|
1612
|
+
if (v !== u)
|
|
1613
|
+
changed = true;
|
|
1614
|
+
instantiated.push(v);
|
|
1615
|
+
}
|
|
1616
|
+
return changed ? getIntersectionType(c, instantiated) : t;
|
|
1617
|
+
}
|
|
1618
|
+
return t;
|
|
1619
|
+
}
|
|
1620
|
+
/** The applicable signatures, instantiated; the same array when nothing changes. */
|
|
1621
|
+
instantiateSignatures(signatures) {
|
|
1622
|
+
const c = this.c;
|
|
1623
|
+
const result = [];
|
|
1624
|
+
let changed = false;
|
|
1625
|
+
for (const sig of signatures) {
|
|
1626
|
+
if (sig.typeParameters.length === 0 || !hasCorrectTypeArgumentArity(c, sig, this.typeArguments)) {
|
|
1627
|
+
changed = true;
|
|
1628
|
+
continue;
|
|
1629
|
+
}
|
|
1630
|
+
const typeArgumentTypes = checkTypeArguments(c, sig, this.typeArguments, true, undefined);
|
|
1631
|
+
if (typeArgumentTypes === undefined) {
|
|
1632
|
+
result.push(sig);
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
result.push(getSignatureInstantiation(c, sig, typeArgumentTypes, isInJSFile(sig.declaration)));
|
|
1636
|
+
changed = true;
|
|
1637
|
+
}
|
|
1638
|
+
return changed ? result : signatures;
|
|
1639
|
+
}
|
|
1640
|
+
}
|