tsc-ts 0.0.9 → 0.1.0
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 +2 -2
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +22 -15
- package/dist/api/compiler/ast.js +1026 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +178 -124
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +472 -440
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -107
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +212 -75
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +145 -36
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +104 -31
- package/dist/api/compiler/checker.js +181 -33
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +42 -3
- package/dist/api/compiler/compile-program.js +139 -27
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.d.ts +22 -0
- package/dist/api/compiler/diagnostics.js +93 -11
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +21 -1
- package/dist/api/compiler/file-loader.js +201 -48
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parallel-parse.d.ts +3 -2
- package/dist/api/compiler/parallel-parse.js +17 -5
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +5 -1
- package/dist/api/compiler/printer/emit-context.js +20 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +49 -2
- package/dist/api/compiler/printer/printer.js +539 -293
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +12 -2
- package/dist/api/compiler/program-checker.js +88 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +4 -6
- package/dist/api/compiler/program.js +74 -87
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +347 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +23 -14
- package/dist/api/compiler/symbol.js +23 -11
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +58 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +79 -9
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +136 -62
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -82
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +200 -56
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +124 -23
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +203 -39
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +167 -27
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/diagnostics.ts +84 -3
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +197 -38
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +165 -30
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +326 -52
- package/src/compiler/parallel-emit.ts +320 -0
- package/src/compiler/parallel-parse.ts +16 -5
- package/src/compiler/parse-thread.ts +3 -0
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +21 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +266 -30
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +57 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +18 -26
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +240 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +46 -24
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +64 -4
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +66 -9
- package/src/compiler/tsc-cli.ts +7 -0
- package/src/compiler/tsc-compile.ts +284 -4
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -7,9 +7,9 @@ import { getCombinedModifierFlags } from './binder-utilities.js';
|
|
|
7
7
|
import { Diagnostic, messageElidedInCompatibilityPyramid } from './diagnostics.js';
|
|
8
8
|
import { isContextSensitive } from './checker-functions.js';
|
|
9
9
|
import { createDiagnosticForNode } from './checker.js';
|
|
10
|
-
import { cachedTypeKey, emptyTypes, newTypeMapper, SimpleTypeMapper, } from './checker-types.js';
|
|
10
|
+
import { cachedTypeKey, emptyTypes, newTypeMapper, SimpleTypeMapper, isDistributedTypeParameter, } from './checker-types.js';
|
|
11
11
|
import { createInferenceContext, inferTypes } from './checker-inference.js';
|
|
12
|
-
import { unionContainsSortedTypes, unionContainsType, createArrayTypeEx, compareTypes, containsMissingType, createTypeReference, everyType, filterType, getBaseTypeOfLiteralType, getBaseTypeOfEnumLikeType, getElementTypes, getIntersectionType, getIntersectionTypeEx, getTargetType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, isArrayOrTupleType, isArrayType, isEmptyAnonymousObjectType, isEmptyObjectType, isErrorType, isFreshLiteralType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, isUnitType, someType, tupleTargetOf, typesOf, countTypes, getStartElementCount, getEndElementCount, createNormalizedTypeReference, typeListKey, getRegularTypeOfLiteralType, } from './checker-type-factory.js';
|
|
12
|
+
import { unionContainsSortedTypes, unionContainsType, createArrayTypeEx, compareTypes, containsMissingType, createTypeReference, everyType, filterType, getBaseTypeOfLiteralType, getBaseTypeOfEnumLikeType, getElementTypes, getIntersectionType, getIntersectionTypeEx, getTargetType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, isArrayOrTupleType, isArrayType, isEmptyAnonymousObjectType, isEmptyObjectType, isErrorType, isFreshLiteralType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, isUnitType, someType, tupleTargetOf, typesOf, countTypes, getStartElementCount, getEndElementCount, createNormalizedTypeReference, typeListKey, getRegularTypeOfLiteralType, compareSymbols, } from './checker-type-factory.js';
|
|
13
13
|
import { findApplicableIndexInfo, getApparentType, getApplicableIndexInfo, getApplicableIndexInfoForName, getBaseConstraintOfType, getBaseConstraintOrType, getConstraintOfType, getDeclarationModifierFlagsFromSymbol, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getPropertiesOfObjectType, getPropertiesOfType, getPropertiesOfUnionOrIntersectionType, getPropertyOfObjectType, getPropertyOfType, getPropertyOfUnionOrIntersectionType, getReducedType, getSignaturesOfStructuredType, getSignaturesOfType, getTargetSymbol, getTypeOfPropertyOfType, getTypeWithThisArgument, getUnionOrIntersectionProperty, isApplicableIndexType, isArrayLikeType, isObjectLiteralType, isDiscriminantWithNeverType, isConflictingPrivateProperty, resolveStructuredTypeMembers, getResolvedMember, hasResolvedProperties, resolvedPropertiesAreOptional, positionsOfNamesFoundInSource, firstUnmatchedProperty, } from './checker-members.js';
|
|
14
14
|
import { getParentOfSymbol, getMergedSymbol, getMembersOfSymbol, getSpellingSuggestionForName, } from './checker-symbols.js';
|
|
15
15
|
import { CodePoints, distanceToCandidate, utf8Length } from './spelling.js';
|
|
@@ -45,6 +45,7 @@ export class Relation {
|
|
|
45
45
|
return 0 /* RelationComparisonResult.None */;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
/** Sets the result of `key`, and returns whether the key is new. */
|
|
48
49
|
set(key, result) {
|
|
49
50
|
const keys = this.keys;
|
|
50
51
|
const mask = keys.length - 1;
|
|
@@ -52,7 +53,7 @@ export class Relation {
|
|
|
52
53
|
const k = keys[i];
|
|
53
54
|
if (k === key) {
|
|
54
55
|
this.results[i] = result;
|
|
55
|
-
return;
|
|
56
|
+
return false;
|
|
56
57
|
}
|
|
57
58
|
if (k === 0) {
|
|
58
59
|
keys[i] = key;
|
|
@@ -60,10 +61,32 @@ export class Relation {
|
|
|
60
61
|
this.count++;
|
|
61
62
|
if (this.count * 4 > keys.length * 3)
|
|
62
63
|
this.grow();
|
|
63
|
-
return;
|
|
64
|
+
return true;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
/** Removes `key`, moving later entries of its probe run back so lookups still find them. */
|
|
69
|
+
delete(key) {
|
|
70
|
+
const keys = this.keys;
|
|
71
|
+
const results = this.results;
|
|
72
|
+
const mask = keys.length - 1;
|
|
73
|
+
let i = relationSlot(key) & mask;
|
|
74
|
+
for (; keys[i] !== key; i = (i + 1) & mask)
|
|
75
|
+
if (keys[i] === 0)
|
|
76
|
+
return;
|
|
77
|
+
for (let j = (i + 1) & mask; keys[j] !== 0; j = (j + 1) & mask) {
|
|
78
|
+
// An entry stays where it is when its home slot is cyclically after the freed slot and at or before it.
|
|
79
|
+
const home = relationSlot(keys[j]) & mask;
|
|
80
|
+
if (i <= j ? i < home && home <= j : i < home || home <= j)
|
|
81
|
+
continue;
|
|
82
|
+
keys[i] = keys[j];
|
|
83
|
+
results[i] = results[j];
|
|
84
|
+
i = j;
|
|
85
|
+
}
|
|
86
|
+
keys[i] = 0;
|
|
87
|
+
results[i] = 0;
|
|
88
|
+
this.count--;
|
|
89
|
+
}
|
|
67
90
|
size() {
|
|
68
91
|
return this.count;
|
|
69
92
|
}
|
|
@@ -232,6 +255,16 @@ export function isTypeRelatedTo(c, source, target, relation) {
|
|
|
232
255
|
if ((source.flags & 394239 /* TypeFlags.Singleton */) !== 0)
|
|
233
256
|
return true;
|
|
234
257
|
}
|
|
258
|
+
else {
|
|
259
|
+
// What the relater decides first for types that may simplify (Relater.isRelatedToEx): their normal forms are
|
|
260
|
+
// one type, or can be identical only with identical flags.
|
|
261
|
+
const s = getNormalizedType(c, source, false);
|
|
262
|
+
const t = getNormalizedType(c, target, true);
|
|
263
|
+
if (s === t)
|
|
264
|
+
return true;
|
|
265
|
+
if (s.flags !== t.flags)
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
235
268
|
if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
236
269
|
const related = relation.get(getRelationKey(c, source, target, 0 /* IntersectionState.None */, relation === c.identityRelation, false).key);
|
|
237
270
|
if (related !== 0 /* RelationComparisonResult.None */)
|
|
@@ -423,15 +456,15 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
423
456
|
const targetProperty = getPropertyOfType(c, targetEnumType, sourceProperty.name);
|
|
424
457
|
if (targetProperty === undefined || (targetProperty.flags & 8 /* SymbolFlags.EnumMember */) === 0) {
|
|
425
458
|
if (reporter !== undefined)
|
|
426
|
-
reporter.reportError(
|
|
459
|
+
reporter.reportError(509 /* Diagnostics.Property_0_is_missing_in_type_1 */, [
|
|
427
460
|
symbolToString(c, sourceProperty),
|
|
428
461
|
typeToString(c, getDeclaredTypeOfSymbol(c, targetSymbol), undefined, 1 << 6),
|
|
429
462
|
]);
|
|
430
463
|
c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
|
|
431
464
|
return false;
|
|
432
465
|
}
|
|
433
|
-
const sourceDecl = getDeclarations(sourceProperty).find((d) => d.kind ===
|
|
434
|
-
const targetDecl = getDeclarations(targetProperty).find((d) => d.kind ===
|
|
466
|
+
const sourceDecl = getDeclarations(sourceProperty).find((d) => d.kind === 307 /* SyntaxKind.EnumMember */);
|
|
467
|
+
const targetDecl = getDeclarations(targetProperty).find((d) => d.kind === 307 /* SyntaxKind.EnumMember */);
|
|
435
468
|
if (sourceDecl === undefined || targetDecl === undefined)
|
|
436
469
|
continue;
|
|
437
470
|
computeEnumMemberValues(c, sourceDecl.parent);
|
|
@@ -445,7 +478,7 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
445
478
|
continue;
|
|
446
479
|
if (s.enumValueKind !== 0 && t.enumValueKind !== 0) {
|
|
447
480
|
if (reporter !== undefined)
|
|
448
|
-
reporter.reportError(
|
|
481
|
+
reporter.reportError(1118 /* Diagnostics.Each_declaration_of_0_1_differs_in_its_value_where_2_was_expected_but_3_was_given */, [
|
|
449
482
|
symbolToString(c, targetSymbol),
|
|
450
483
|
symbolToString(c, targetProperty),
|
|
451
484
|
enumValueText(t.enumValueKind, t.enumNumberValue, t.enumStringValue),
|
|
@@ -458,7 +491,7 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
458
491
|
if (s.enumValueKind === 2 || t.enumValueKind === 2) {
|
|
459
492
|
if (reporter !== undefined) {
|
|
460
493
|
const known = s.enumValueKind === 2 ? s : t;
|
|
461
|
-
reporter.reportError(
|
|
494
|
+
reporter.reportError(1119 /* Diagnostics.One_value_of_0_1_is_the_string_2_and_the_other_is_assumed_to_be_an_unknown_numeric_value */, [symbolToString(c, targetSymbol), symbolToString(c, targetProperty), JSON.stringify(known.enumStringValue)]);
|
|
462
495
|
}
|
|
463
496
|
c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
|
|
464
497
|
return false;
|
|
@@ -613,20 +646,35 @@ export function checkTypeRelatedTo(c, source, target, relation, errorNode, headM
|
|
|
613
646
|
// Nested checks (from resolving types during the relation) find no spare and allocate their own.
|
|
614
647
|
const r = c.spareRelater ?? new Relater(c, relation, errorNode);
|
|
615
648
|
c.spareRelater = undefined;
|
|
649
|
+
const relationCount = Math.trunc((16000000 - relation.size()) / 8);
|
|
650
|
+
if (errorNode !== undefined) {
|
|
651
|
+
// Relate without reporting first: reporting builds a message for every comparison that fails on the way,
|
|
652
|
+
// even when the relation holds. When the relation fails, the results this pass added are removed, since
|
|
653
|
+
// the comparisons it assumed related while comparing would change which failure the report elaborates.
|
|
654
|
+
r.reset(relation, undefined);
|
|
655
|
+
r.relationCount = relationCount;
|
|
656
|
+
const addedKeys = [];
|
|
657
|
+
r.addedKeys = addedKeys;
|
|
658
|
+
const quiet = r.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, false, undefined, 0 /* IntersectionState.None */);
|
|
659
|
+
r.addedKeys = undefined;
|
|
660
|
+
if (quiet !== 0 /* Ternary.False */ && !r.overflow) {
|
|
661
|
+
c.spareRelater = r;
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
for (const key of addedKeys)
|
|
665
|
+
relation.delete(key);
|
|
666
|
+
}
|
|
616
667
|
r.reset(relation, errorNode);
|
|
617
|
-
r.relationCount =
|
|
668
|
+
r.relationCount = relationCount;
|
|
618
669
|
const result = r.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, errorNode !== undefined, headMessage, 0 /* IntersectionState.None */);
|
|
619
670
|
if (r.overflow) {
|
|
620
671
|
// Remember the overflow so it isn't attempted again.
|
|
621
672
|
const key = getRelationKey(c, source, target, 0 /* IntersectionState.None */, relation === c.identityRelation, false).key;
|
|
622
|
-
relation.set(key, 2 /* RelationComparisonResult.Failed */ |
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
? 979 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */
|
|
628
|
-
: 499 /* Diagnostics.Excessive_stack_depth_comparing_types_0_and_1 */;
|
|
629
|
-
reportDiagnostic(c, createDiagnosticForNode(errorNode ?? c.currentNode, message, [typeToString(c, source), typeToString(c, target)]), diagnosticOutput);
|
|
673
|
+
relation.set(key, 2 /* RelationComparisonResult.Failed */ | 32 /* RelationComparisonResult.ComplexityOverflow */);
|
|
674
|
+
reportDiagnostic(c, createDiagnosticForNode(errorNode ?? c.currentNode, 986 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */, [
|
|
675
|
+
typeToString(c, source),
|
|
676
|
+
typeToString(c, target),
|
|
677
|
+
]), diagnosticOutput);
|
|
630
678
|
}
|
|
631
679
|
else if (r.errorChain !== undefined) {
|
|
632
680
|
const diagnostic = createDiagnosticFromErrorChain(r.errorChain, r.errorNode, r.relatedInfo);
|
|
@@ -709,14 +757,14 @@ function addToDottedName(head, tail) {
|
|
|
709
757
|
return suffix.startsWith('[') ? prefix + head + suffix : prefix + head + '.' + suffix;
|
|
710
758
|
}
|
|
711
759
|
function isConversionOrInterfaceImplementationMessage(message) {
|
|
712
|
-
return (message ===
|
|
760
|
+
return (message === 598 /* Diagnostics.Class_0_incorrectly_implements_interface_1 */ ||
|
|
713
761
|
message ===
|
|
714
|
-
|
|
762
|
+
859 /* Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass */ ||
|
|
715
763
|
message ===
|
|
716
|
-
|
|
717
|
-
message ===
|
|
718
|
-
message ===
|
|
719
|
-
message ===
|
|
764
|
+
535 /* Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first */ ||
|
|
765
|
+
message === 927 /* Diagnostics.Its_instance_type_0_is_not_a_valid_JSX_element */ ||
|
|
766
|
+
message === 926 /* Diagnostics.Its_return_type_0_is_not_a_valid_JSX_element */ ||
|
|
767
|
+
message === 928 /* Diagnostics.Its_element_type_0_is_not_a_valid_JSX_element */);
|
|
720
768
|
}
|
|
721
769
|
// ---- The relater
|
|
722
770
|
/** The state of a relation check: its error chain, maybe-stack and recursion stacks. */
|
|
@@ -736,6 +784,8 @@ export class Relater extends TypeComparer {
|
|
|
736
784
|
expandingFlags = 0 /* ExpandingFlags.None */;
|
|
737
785
|
overflow = false;
|
|
738
786
|
relationCount = 0;
|
|
787
|
+
/** The keys this check added to the relation, while relating without reporting first. */
|
|
788
|
+
addedKeys = undefined;
|
|
739
789
|
/** The intersection state passed to `compare` during signature comparisons. */
|
|
740
790
|
signatureIntersectionState = 0 /* IntersectionState.None */;
|
|
741
791
|
// What `relateVariances` changes in its caller's state when it falls back to structure.
|
|
@@ -858,9 +908,9 @@ export class Relater extends TypeComparer {
|
|
|
858
908
|
(constructs.length > 0 &&
|
|
859
909
|
this.isRelatedTo(getReturnTypeOfSignature(c, constructs[0]), target, 1 /* RecursionFlags.Source */, false) !==
|
|
860
910
|
0 /* Ternary.False */))
|
|
861
|
-
this.reportError(
|
|
911
|
+
this.reportError(721 /* Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it */, [sourceString, targetString]);
|
|
862
912
|
else
|
|
863
|
-
this.reportError(
|
|
913
|
+
this.reportError(720 /* Diagnostics.Type_0_has_no_properties_in_common_with_type_1 */, [sourceString, targetString]);
|
|
864
914
|
}
|
|
865
915
|
return 0 /* Ternary.False */;
|
|
866
916
|
}
|
|
@@ -909,25 +959,25 @@ export class Relater extends TypeComparer {
|
|
|
909
959
|
// Report in terms of the object types we check in isKnownProperty, at the property.
|
|
910
960
|
const errorTarget = filterType(c, reducedTarget, isExcessPropertyCheckTarget);
|
|
911
961
|
const errorNode = this.errorNode;
|
|
912
|
-
if (errorNode.kind ===
|
|
962
|
+
if (errorNode.kind === 294 /* SyntaxKind.JsxAttributes */ ||
|
|
913
963
|
isJsxOpeningLikeElement(errorNode) ||
|
|
914
964
|
(errorNode.parent !== undefined && isJsxOpeningLikeElement(errorNode.parent))) {
|
|
915
965
|
// Attributes are checked like object literals but reported as attributes, at the attribute.
|
|
916
966
|
const valueDeclaration = prop.valueDeclaration;
|
|
917
967
|
if (valueDeclaration !== undefined &&
|
|
918
|
-
valueDeclaration.kind ===
|
|
968
|
+
valueDeclaration.kind === 293 /* SyntaxKind.JsxAttribute */ &&
|
|
919
969
|
sameFile(valueDeclaration, errorNode))
|
|
920
970
|
this.errorNode = getName(valueDeclaration);
|
|
921
971
|
const propName = symbolToString(c, prop);
|
|
922
972
|
const suggestion = getSuggestedSymbolForNonexistentJSXAttribute(c, propName, errorTarget);
|
|
923
973
|
if (suggestion !== undefined)
|
|
924
|
-
this.reportError(
|
|
974
|
+
this.reportError(713 /* Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2 */, [
|
|
925
975
|
propName,
|
|
926
976
|
typeToString(c, errorTarget),
|
|
927
977
|
symbolToString(c, suggestion),
|
|
928
978
|
]);
|
|
929
979
|
else
|
|
930
|
-
this.reportError(
|
|
980
|
+
this.reportError(523 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
|
|
931
981
|
propName,
|
|
932
982
|
typeToString(c, errorTarget),
|
|
933
983
|
]);
|
|
@@ -949,16 +999,16 @@ export class Relater extends TypeComparer {
|
|
|
949
999
|
suggestion = getSpellingSuggestionForName(c, getText(name), getPropertiesOfType(c, errorTarget), 111551 /* SymbolFlags.Value */);
|
|
950
1000
|
}
|
|
951
1001
|
if (suggestion !== undefined)
|
|
952
|
-
this.reportError(
|
|
1002
|
+
this.reportError(722 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */, [symbolToString(c, prop), typeToString(c, errorTarget), suggestion.name]);
|
|
953
1003
|
else
|
|
954
|
-
this.reportError(
|
|
1004
|
+
this.reportError(536 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */, [symbolToString(c, prop), typeToString(c, errorTarget)]);
|
|
955
1005
|
}
|
|
956
1006
|
return true;
|
|
957
1007
|
}
|
|
958
1008
|
if (checkTypes !== undefined &&
|
|
959
1009
|
this.isRelatedTo(getTypeOfSymbol(c, prop), getTypeOfPropertyInTypes(c, checkTypes, prop.name), 3 /* RecursionFlags.Both */, reportErrors) === 0 /* Ternary.False */) {
|
|
960
1010
|
if (reportErrors)
|
|
961
|
-
this.reportError(
|
|
1011
|
+
this.reportError(511 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, prop)]);
|
|
962
1012
|
return true;
|
|
963
1013
|
}
|
|
964
1014
|
}
|
|
@@ -1125,18 +1175,17 @@ export class Relater extends TypeComparer {
|
|
|
1125
1175
|
if (entry !== 0 /* RelationComparisonResult.None */) {
|
|
1126
1176
|
if (reportErrors &&
|
|
1127
1177
|
(entry & 2 /* RelationComparisonResult.Failed */) !== 0 &&
|
|
1128
|
-
(entry &
|
|
1178
|
+
(entry & 32 /* RelationComparisonResult.Overflow */) === 0) {
|
|
1129
1179
|
// Redo the failed comparison to elaborate.
|
|
1130
1180
|
}
|
|
1131
1181
|
else {
|
|
1132
1182
|
c.reliabilityFlags |=
|
|
1133
1183
|
entry & (8 /* RelationComparisonResult.ReportsUnmeasurable */ | 16 /* RelationComparisonResult.ReportsUnreliable */);
|
|
1134
|
-
if (reportErrors && (entry &
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1184
|
+
if (reportErrors && (entry & 32 /* RelationComparisonResult.Overflow */) !== 0)
|
|
1185
|
+
this.reportError(986 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */, [
|
|
1186
|
+
typeToString(c, source),
|
|
1187
|
+
typeToString(c, target),
|
|
1188
|
+
]);
|
|
1140
1189
|
return (entry & 1 /* RelationComparisonResult.Succeeded */) !== 0 ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
|
|
1141
1190
|
}
|
|
1142
1191
|
}
|
|
@@ -1154,10 +1203,10 @@ export class Relater extends TypeComparer {
|
|
|
1154
1203
|
}
|
|
1155
1204
|
const sourceDepth = this.sourceDepth;
|
|
1156
1205
|
const targetDepth = this.targetDepth;
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1206
|
+
// A backstop for infinite recursion that isDeeplyNestedType misses, which also stops relating the exceedingly
|
|
1207
|
+
// rare types that are truly more than 100 levels deep.
|
|
1208
|
+
if (sourceDepth === 100 || targetDepth === 100)
|
|
1209
|
+
return 3 /* Ternary.Maybe */;
|
|
1161
1210
|
const maybeStart = this.maybeKeys.length;
|
|
1162
1211
|
this.maybeKeys.push(id);
|
|
1163
1212
|
this.maybeKeysSet.add(id);
|
|
@@ -1194,17 +1243,21 @@ export class Relater extends TypeComparer {
|
|
|
1194
1243
|
}
|
|
1195
1244
|
else {
|
|
1196
1245
|
// False under assumptions is false without them.
|
|
1197
|
-
this.
|
|
1246
|
+
this.record(id, 2 /* RelationComparisonResult.Failed */ | propagatingVarianceFlags);
|
|
1198
1247
|
this.relationCount--;
|
|
1199
1248
|
this.resetMaybeStack(maybeStart, propagatingVarianceFlags, false);
|
|
1200
1249
|
}
|
|
1201
1250
|
return result;
|
|
1202
1251
|
}
|
|
1252
|
+
record(key, result) {
|
|
1253
|
+
if (this.relation.set(key, result) && this.addedKeys !== undefined)
|
|
1254
|
+
this.addedKeys.push(key);
|
|
1255
|
+
}
|
|
1203
1256
|
resetMaybeStack(maybeStart, propagatingVarianceFlags, markAllAsSucceeded) {
|
|
1204
1257
|
for (let i = maybeStart; i < this.maybeKeys.length; i++) {
|
|
1205
1258
|
this.maybeKeysSet.delete(this.maybeKeys[i]);
|
|
1206
1259
|
if (markAllAsSucceeded) {
|
|
1207
|
-
this.
|
|
1260
|
+
this.record(this.maybeKeys[i], 1 /* RelationComparisonResult.Succeeded */ | propagatingVarianceFlags);
|
|
1208
1261
|
this.relationCount--;
|
|
1209
1262
|
}
|
|
1210
1263
|
}
|
|
@@ -1897,7 +1950,7 @@ export class Relater extends TypeComparer {
|
|
|
1897
1950
|
? this.isRelatedTo(s, t, 3 /* RecursionFlags.Both */, false)
|
|
1898
1951
|
: compareTypesIdentical(c, s, t);
|
|
1899
1952
|
else {
|
|
1900
|
-
if (c.
|
|
1953
|
+
if (c.varianceStack.length !== 0 && (varianceFlags & 16 /* VarianceFlags.Unreliable */) !== 0)
|
|
1901
1954
|
instantiateType(c, s, c.reportUnreliableMapper);
|
|
1902
1955
|
if (variance === 1 /* VarianceFlags.Covariant */)
|
|
1903
1956
|
related = this.isRelatedToEx(s, t, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
@@ -1958,33 +2011,34 @@ export class Relater extends TypeComparer {
|
|
|
1958
2011
|
const sourceArity = getTypeReferenceArity(source);
|
|
1959
2012
|
const targetArity = getTypeReferenceArity(target);
|
|
1960
2013
|
const sourceRest = isTupleType(source) ? (tupleTargetOf(source).combinedFlags & 4 /* ElementFlags.Rest */) !== 0 : true;
|
|
1961
|
-
const targetHasRestElement = (targetTuple.combinedFlags &
|
|
2014
|
+
const targetHasRestElement = (targetTuple.combinedFlags & 4 /* ElementFlags.Rest */) !== 0;
|
|
2015
|
+
const targetHasVariableElement = (targetTuple.combinedFlags & 12 /* ElementFlags.Variable */) !== 0;
|
|
1962
2016
|
const sourceMinLength = isTupleType(source) ? tupleTargetOf(source).minLength : 0;
|
|
1963
2017
|
const targetMinLength = targetTuple.minLength;
|
|
1964
2018
|
if (!sourceRest && sourceArity < targetMinLength) {
|
|
1965
2019
|
if (reportErrors)
|
|
1966
|
-
this.reportError(
|
|
2020
|
+
this.reportError(769 /* Diagnostics.Source_has_0_element_s_but_target_requires_1 */, [
|
|
1967
2021
|
String(sourceArity),
|
|
1968
2022
|
String(targetMinLength),
|
|
1969
2023
|
]);
|
|
1970
2024
|
return 0 /* Ternary.False */;
|
|
1971
2025
|
}
|
|
1972
|
-
if (!
|
|
2026
|
+
if (!targetHasVariableElement && targetArity < sourceMinLength) {
|
|
1973
2027
|
if (reportErrors)
|
|
1974
|
-
this.reportError(
|
|
2028
|
+
this.reportError(770 /* Diagnostics.Source_has_0_element_s_but_target_allows_only_1 */, [
|
|
1975
2029
|
String(sourceMinLength),
|
|
1976
2030
|
String(targetArity),
|
|
1977
2031
|
]);
|
|
1978
2032
|
return 0 /* Ternary.False */;
|
|
1979
2033
|
}
|
|
1980
|
-
if (!
|
|
2034
|
+
if (!targetHasVariableElement && (sourceRest || targetArity < sourceArity)) {
|
|
1981
2035
|
if (reportErrors) {
|
|
1982
2036
|
if (sourceMinLength < targetMinLength)
|
|
1983
|
-
this.reportError(
|
|
2037
|
+
this.reportError(771 /* Diagnostics.Target_requires_0_element_s_but_source_may_have_fewer */, [
|
|
1984
2038
|
String(targetMinLength),
|
|
1985
2039
|
]);
|
|
1986
2040
|
else
|
|
1987
|
-
this.reportError(
|
|
2041
|
+
this.reportError(772 /* Diagnostics.Target_allows_only_0_element_s_but_source_may_have_more */, [
|
|
1988
2042
|
String(targetArity),
|
|
1989
2043
|
]);
|
|
1990
2044
|
}
|
|
@@ -2000,25 +2054,34 @@ export class Relater extends TypeComparer {
|
|
|
2000
2054
|
? tupleTargetOf(source).elementInfos[sourcePosition].flags
|
|
2001
2055
|
: 4 /* ElementFlags.Rest */;
|
|
2002
2056
|
const sourcePositionFromEnd = sourceArity - 1 - sourcePosition;
|
|
2003
|
-
const
|
|
2057
|
+
const restMapped = targetHasRestElement && sourcePosition >= targetStartCount;
|
|
2058
|
+
// A source element past the target's last element (a target with variadic but no rest elements).
|
|
2059
|
+
if (!restMapped && sourcePosition >= targetArity) {
|
|
2060
|
+
if (reportErrors)
|
|
2061
|
+
this.reportError(772 /* Diagnostics.Target_allows_only_0_element_s_but_source_may_have_more */, [
|
|
2062
|
+
String(targetArity),
|
|
2063
|
+
]);
|
|
2064
|
+
return 0 /* Ternary.False */;
|
|
2065
|
+
}
|
|
2066
|
+
const targetPosition = restMapped
|
|
2004
2067
|
? targetArity - 1 - Math.min(sourcePositionFromEnd, targetEndCount)
|
|
2005
2068
|
: sourcePosition;
|
|
2006
2069
|
const targetFlags = targetPosition >= 0 ? targetTuple.elementInfos[targetPosition].flags : 0 /* ElementFlags.None */;
|
|
2007
2070
|
if ((targetFlags & 8 /* ElementFlags.Variadic */) !== 0 && (sourceFlags & 8 /* ElementFlags.Variadic */) === 0) {
|
|
2008
2071
|
if (reportErrors)
|
|
2009
|
-
this.reportError(
|
|
2072
|
+
this.reportError(774 /* Diagnostics.Source_provides_no_match_for_variadic_element_at_position_0_in_target */, [
|
|
2010
2073
|
String(targetPosition),
|
|
2011
2074
|
]);
|
|
2012
2075
|
return 0 /* Ternary.False */;
|
|
2013
2076
|
}
|
|
2014
2077
|
if ((sourceFlags & 8 /* ElementFlags.Variadic */) !== 0 && (targetFlags & 12 /* ElementFlags.Variable */) === 0) {
|
|
2015
2078
|
if (reportErrors)
|
|
2016
|
-
this.reportError(
|
|
2079
|
+
this.reportError(775 /* Diagnostics.Variadic_element_at_position_0_in_source_does_not_match_element_at_position_1_in_target */, [String(sourcePosition), String(targetPosition)]);
|
|
2017
2080
|
return 0 /* Ternary.False */;
|
|
2018
2081
|
}
|
|
2019
2082
|
if ((targetFlags & 1 /* ElementFlags.Required */) !== 0 && (sourceFlags & 1 /* ElementFlags.Required */) === 0) {
|
|
2020
2083
|
if (reportErrors)
|
|
2021
|
-
this.reportError(
|
|
2084
|
+
this.reportError(773 /* Diagnostics.Source_provides_no_match_for_required_element_at_position_0_in_target */, [
|
|
2022
2085
|
String(targetPosition),
|
|
2023
2086
|
]);
|
|
2024
2087
|
return 0 /* Ternary.False */;
|
|
@@ -2041,9 +2104,9 @@ export class Relater extends TypeComparer {
|
|
|
2041
2104
|
sourcePosition >= targetStartCount &&
|
|
2042
2105
|
sourcePositionFromEnd >= targetEndCount &&
|
|
2043
2106
|
targetStartCount !== sourceArity - targetEndCount - 1)
|
|
2044
|
-
this.reportError(
|
|
2107
|
+
this.reportError(777 /* Diagnostics.Type_at_positions_0_through_1_in_source_is_not_compatible_with_type_at_position_2_in_target */, [String(targetStartCount), String(sourceArity - targetEndCount - 1), String(targetPosition)]);
|
|
2045
2108
|
else
|
|
2046
|
-
this.reportError(
|
|
2109
|
+
this.reportError(776 /* Diagnostics.Type_at_position_0_in_source_is_not_compatible_with_type_at_position_1_in_target */, [String(sourcePosition), String(targetPosition)]);
|
|
2047
2110
|
}
|
|
2048
2111
|
return 0 /* Ternary.False */;
|
|
2049
2112
|
}
|
|
@@ -2075,7 +2138,7 @@ export class Relater extends TypeComparer {
|
|
|
2075
2138
|
continue;
|
|
2076
2139
|
if (getPropertyOfObjectType(c, target, sourceProp.name) === undefined) {
|
|
2077
2140
|
if (reportErrors)
|
|
2078
|
-
this.reportError(
|
|
2141
|
+
this.reportError(523 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
|
|
2079
2142
|
symbolToString(c, sourceProp),
|
|
2080
2143
|
typeToString(c, target),
|
|
2081
2144
|
]);
|
|
@@ -2114,12 +2177,12 @@ export class Relater extends TypeComparer {
|
|
|
2114
2177
|
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
|
|
2115
2178
|
if (reportErrors) {
|
|
2116
2179
|
if ((sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0 && (targetPropFlags & 2 /* ModifierFlags.Private */) !== 0)
|
|
2117
|
-
this.reportError(
|
|
2180
|
+
this.reportError(617 /* Diagnostics.Types_have_separate_declarations_of_a_private_property_0 */, [
|
|
2118
2181
|
symbolToString(c, targetProp),
|
|
2119
2182
|
]);
|
|
2120
2183
|
else {
|
|
2121
2184
|
const sourceIsPrivate = (sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0;
|
|
2122
|
-
this.reportError(
|
|
2185
|
+
this.reportError(510 /* Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2 */, [
|
|
2123
2186
|
symbolToString(c, targetProp),
|
|
2124
2187
|
typeToString(c, sourceIsPrivate ? source : target),
|
|
2125
2188
|
typeToString(c, sourceIsPrivate ? target : source),
|
|
@@ -2132,7 +2195,7 @@ export class Relater extends TypeComparer {
|
|
|
2132
2195
|
else if ((targetPropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
|
|
2133
2196
|
if (!isValidOverrideOf(c, sourceProp, targetProp)) {
|
|
2134
2197
|
if (reportErrors)
|
|
2135
|
-
this.reportError(
|
|
2198
|
+
this.reportError(618 /* Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2 */, [
|
|
2136
2199
|
symbolToString(c, targetProp),
|
|
2137
2200
|
typeToString(c, getDeclaringClass(c, sourceProp) ?? source),
|
|
2138
2201
|
typeToString(c, getDeclaringClass(c, targetProp) ?? target),
|
|
@@ -2142,7 +2205,7 @@ export class Relater extends TypeComparer {
|
|
|
2142
2205
|
}
|
|
2143
2206
|
else if ((sourcePropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
|
|
2144
2207
|
if (reportErrors)
|
|
2145
|
-
this.reportError(
|
|
2208
|
+
this.reportError(619 /* Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2 */, [
|
|
2146
2209
|
symbolToString(c, targetProp),
|
|
2147
2210
|
typeToString(c, source),
|
|
2148
2211
|
typeToString(c, target),
|
|
@@ -2157,7 +2220,7 @@ export class Relater extends TypeComparer {
|
|
|
2157
2220
|
const related = this.isPropertySymbolTypeRelated(sourceProp, targetProp, sourcePropType, reportErrors, intersectionState);
|
|
2158
2221
|
if (related === 0 /* Ternary.False */) {
|
|
2159
2222
|
if (reportErrors)
|
|
2160
|
-
this.reportError(
|
|
2223
|
+
this.reportError(511 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, targetProp)]);
|
|
2161
2224
|
return 0 /* Ternary.False */;
|
|
2162
2225
|
}
|
|
2163
2226
|
if (!skipOptional &&
|
|
@@ -2165,7 +2228,7 @@ export class Relater extends TypeComparer {
|
|
|
2165
2228
|
(targetProp.flags & 106500 /* SymbolFlags.ClassMember */) !== 0 &&
|
|
2166
2229
|
(targetProp.flags & 16777216 /* SymbolFlags.Optional */) === 0) {
|
|
2167
2230
|
if (reportErrors)
|
|
2168
|
-
this.reportError(
|
|
2231
|
+
this.reportError(512 /* Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2 */, [
|
|
2169
2232
|
symbolToString(c, targetProp),
|
|
2170
2233
|
typeToString(c, source),
|
|
2171
2234
|
typeToString(c, target),
|
|
@@ -2194,7 +2257,7 @@ export class Relater extends TypeComparer {
|
|
|
2194
2257
|
(source.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
|
|
2195
2258
|
const description = getText(declarationName);
|
|
2196
2259
|
if (getPropertyOfType(c, source, getSymbolNameForPrivateIdentifier(source.symbol, description)) !== undefined) {
|
|
2197
|
-
this.reportError(
|
|
2260
|
+
this.reportError(1857 /* Diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2 */, [description, symbolToString(c, source.symbol), symbolToString(c, target.symbol)]);
|
|
2198
2261
|
return;
|
|
2199
2262
|
}
|
|
2200
2263
|
}
|
|
@@ -2202,25 +2265,25 @@ export class Relater extends TypeComparer {
|
|
|
2202
2265
|
if (props.length === 1) {
|
|
2203
2266
|
const names = getTypeNamesForErrorDisplay(c, source, target);
|
|
2204
2267
|
const propName = symbolToString(c, unmatchedProperty);
|
|
2205
|
-
this.reportError(
|
|
2268
|
+
this.reportError(880 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */, [
|
|
2206
2269
|
propName,
|
|
2207
2270
|
names[0],
|
|
2208
2271
|
names[1],
|
|
2209
2272
|
]);
|
|
2210
2273
|
if (declarationCount(unmatchedProperty) !== 0)
|
|
2211
|
-
this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declaration,
|
|
2274
|
+
this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declaration, 867 /* Diagnostics.X_0_is_declared_here */, [propName]));
|
|
2212
2275
|
}
|
|
2213
2276
|
else if (this.tryElaborateArrayLikeErrors(source, target, false)) {
|
|
2214
2277
|
const names = getTypeNamesForErrorDisplay(c, source, target);
|
|
2215
2278
|
if (props.length > 5)
|
|
2216
|
-
this.reportError(
|
|
2279
|
+
this.reportError(879 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more */, [
|
|
2217
2280
|
names[0],
|
|
2218
2281
|
names[1],
|
|
2219
2282
|
symbolNames(c, props.slice(0, 4)),
|
|
2220
2283
|
String(props.length - 4),
|
|
2221
2284
|
]);
|
|
2222
2285
|
else
|
|
2223
|
-
this.reportError(
|
|
2286
|
+
this.reportError(878 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2 */, [
|
|
2224
2287
|
names[0],
|
|
2225
2288
|
names[1],
|
|
2226
2289
|
symbolNames(c, props),
|
|
@@ -2233,7 +2296,7 @@ export class Relater extends TypeComparer {
|
|
|
2233
2296
|
if (isTupleType(source)) {
|
|
2234
2297
|
if (tupleTargetOf(source).readonly && isMutableArrayOrTuple(c, target)) {
|
|
2235
2298
|
if (reportErrors)
|
|
2236
|
-
this.reportError(
|
|
2299
|
+
this.reportError(1097 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
|
|
2237
2300
|
typeToString(c, source),
|
|
2238
2301
|
typeToString(c, target),
|
|
2239
2302
|
]);
|
|
@@ -2243,7 +2306,7 @@ export class Relater extends TypeComparer {
|
|
|
2243
2306
|
}
|
|
2244
2307
|
if (isReadonlyArrayType(c, source) && isMutableArrayOrTuple(c, target)) {
|
|
2245
2308
|
if (reportErrors)
|
|
2246
|
-
this.reportError(
|
|
2309
|
+
this.reportError(1097 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
|
|
2247
2310
|
typeToString(c, source),
|
|
2248
2311
|
typeToString(c, target),
|
|
2249
2312
|
]);
|
|
@@ -2292,7 +2355,7 @@ export class Relater extends TypeComparer {
|
|
|
2292
2355
|
const targetIsAbstract = (targetSignatures[0].flags & 8 /* SignatureFlags.Abstract */) !== 0;
|
|
2293
2356
|
if (sourceIsAbstract && !targetIsAbstract) {
|
|
2294
2357
|
if (reportErrors)
|
|
2295
|
-
this.reportError(
|
|
2358
|
+
this.reportError(684 /* Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type */, []);
|
|
2296
2359
|
return 0 /* Ternary.False */;
|
|
2297
2360
|
}
|
|
2298
2361
|
if (!this.constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors))
|
|
@@ -2335,7 +2398,7 @@ export class Relater extends TypeComparer {
|
|
|
2335
2398
|
shouldElaborateErrors = false;
|
|
2336
2399
|
}
|
|
2337
2400
|
if (shouldElaborateErrors)
|
|
2338
|
-
this.reportError(
|
|
2401
|
+
this.reportError(799 /* Diagnostics.Type_0_provides_no_match_for_the_signature_1 */, [
|
|
2339
2402
|
typeToString(c, source),
|
|
2340
2403
|
signatureToString(c, t),
|
|
2341
2404
|
]);
|
|
@@ -2356,7 +2419,7 @@ export class Relater extends TypeComparer {
|
|
|
2356
2419
|
if (targetAccessibility !== 4 /* ModifierFlags.Protected */ && sourceAccessibility === 0)
|
|
2357
2420
|
return true;
|
|
2358
2421
|
if (reportErrors)
|
|
2359
|
-
this.reportError(
|
|
2422
|
+
this.reportError(813 /* Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type */, [
|
|
2360
2423
|
visibilityToString(sourceAccessibility),
|
|
2361
2424
|
visibilityToString(targetAccessibility),
|
|
2362
2425
|
]);
|
|
@@ -2429,7 +2492,7 @@ export class Relater extends TypeComparer {
|
|
|
2429
2492
|
isObjectTypeWithInferableIndex(c, source))
|
|
2430
2493
|
return this.membersRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
|
|
2431
2494
|
if (reportErrors)
|
|
2432
|
-
this.reportError(
|
|
2495
|
+
this.reportError(514 /* Diagnostics.Index_signature_for_type_0_is_missing_in_type_1 */, [
|
|
2433
2496
|
typeToString(c, targetInfo.keyType),
|
|
2434
2497
|
typeToString(c, source),
|
|
2435
2498
|
]);
|
|
@@ -2457,7 +2520,7 @@ export class Relater extends TypeComparer {
|
|
|
2457
2520
|
const related = this.isRelatedToEx(t, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
2458
2521
|
if (related === 0 /* Ternary.False */) {
|
|
2459
2522
|
if (reportErrors)
|
|
2460
|
-
this.reportError(
|
|
2523
|
+
this.reportError(695 /* Diagnostics.Property_0_is_incompatible_with_index_signature */, [symbolToString(c, prop)]);
|
|
2461
2524
|
return 0 /* Ternary.False */;
|
|
2462
2525
|
}
|
|
2463
2526
|
result &= related;
|
|
@@ -2477,9 +2540,9 @@ export class Relater extends TypeComparer {
|
|
|
2477
2540
|
const related = this.isRelatedToEx(sourceInfo.valueType, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
2478
2541
|
if (related === 0 /* Ternary.False */ && reportErrors) {
|
|
2479
2542
|
if (sourceInfo.keyType === targetInfo.keyType)
|
|
2480
|
-
this.reportError(
|
|
2543
|
+
this.reportError(784 /* Diagnostics.X_0_index_signatures_are_incompatible */, [typeToString(c, sourceInfo.keyType)]);
|
|
2481
2544
|
else
|
|
2482
|
-
this.reportError(
|
|
2545
|
+
this.reportError(515 /* Diagnostics.X_0_and_1_index_signatures_are_incompatible */, [
|
|
2483
2546
|
typeToString(c, sourceInfo.keyType),
|
|
2484
2547
|
typeToString(c, targetInfo.keyType),
|
|
2485
2548
|
]);
|
|
@@ -2513,7 +2576,7 @@ export class Relater extends TypeComparer {
|
|
|
2513
2576
|
if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 12713980 /* TypeFlags.Primitive */) !== 0)
|
|
2514
2577
|
this.tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
2515
2578
|
else if (source.symbol !== undefined && (source.flags & 1048576 /* TypeFlags.Object */) !== 0 && c.globalObjectType === source)
|
|
2516
|
-
this.reportError(
|
|
2579
|
+
this.reportError(835 /* Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead */, []);
|
|
2517
2580
|
else if ((source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0 && (target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
2518
2581
|
// Attributes failing JSX.IntrinsicAttributes or JSX.IntrinsicClassAttributes report that member's error alone.
|
|
2519
2582
|
const targetTypes = typesOf(target);
|
|
@@ -2528,7 +2591,7 @@ export class Relater extends TypeComparer {
|
|
|
2528
2591
|
else if ((originalTarget.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
|
|
2529
2592
|
(lazyObjectFlags(c, originalTarget) & 67108864 /* ObjectFlags.IsNeverIntersection */) !== 0) {
|
|
2530
2593
|
const props = getPropertiesOfUnionOrIntersectionType(c, originalTarget);
|
|
2531
|
-
let message =
|
|
2594
|
+
let message = 1868 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents */;
|
|
2532
2595
|
let prop;
|
|
2533
2596
|
for (const p of props) {
|
|
2534
2597
|
if (isDiscriminantWithNeverType(c, p)) {
|
|
@@ -2538,7 +2601,7 @@ export class Relater extends TypeComparer {
|
|
|
2538
2601
|
}
|
|
2539
2602
|
if (prop === undefined) {
|
|
2540
2603
|
message =
|
|
2541
|
-
|
|
2604
|
+
1869 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some */;
|
|
2542
2605
|
for (const p of props) {
|
|
2543
2606
|
if (isConflictingPrivateProperty(p)) {
|
|
2544
2607
|
prop = p;
|
|
@@ -2557,7 +2620,7 @@ export class Relater extends TypeComparer {
|
|
|
2557
2620
|
const syntheticParam = cloneTypeParameter(c, source);
|
|
2558
2621
|
syntheticParam.constraint = instantiateType(c, target, new SimpleTypeMapper(source, syntheticParam));
|
|
2559
2622
|
if (hasNonCircularBaseConstraint(c, syntheticParam)) {
|
|
2560
|
-
this.relatedInfo.push(createDiagnosticForNode(source.symbol.declaration,
|
|
2623
|
+
this.relatedInfo.push(createDiagnosticForNode(source.symbol.declaration, 480 /* Diagnostics.This_type_parameter_might_need_an_extends_0_constraint */, [typeToString(c, target)]));
|
|
2561
2624
|
}
|
|
2562
2625
|
}
|
|
2563
2626
|
}
|
|
@@ -2566,7 +2629,7 @@ export class Relater extends TypeComparer {
|
|
|
2566
2629
|
if ((source === c.globalStringType && target === c.stringType) ||
|
|
2567
2630
|
(source === c.globalNumberType && target === c.numberType) ||
|
|
2568
2631
|
(source === c.globalBooleanType && target === c.booleanType))
|
|
2569
|
-
this.reportError(
|
|
2632
|
+
this.reportError(831 /* Diagnostics.X_0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible */, [
|
|
2570
2633
|
typeToString(c, target),
|
|
2571
2634
|
typeToString(c, source),
|
|
2572
2635
|
]);
|
|
@@ -2592,14 +2655,20 @@ export class Relater extends TypeComparer {
|
|
|
2592
2655
|
target !== c.markerSuperTypeForCheck &&
|
|
2593
2656
|
target !== c.markerSubTypeForCheck) {
|
|
2594
2657
|
const constraint = getBaseConstraintOfType(c, target);
|
|
2595
|
-
if (
|
|
2596
|
-
|
|
2658
|
+
if (isDistributedTypeParameter(target) &&
|
|
2659
|
+
isTypeAssignableTo(c, generalizedSource, target.constraint))
|
|
2660
|
+
this.reportError(1192 /* Diagnostics.X_0_is_only_assignable_to_the_non_distributed_1_but_1_has_been_distributed_here */, [
|
|
2661
|
+
generalizedSourceType,
|
|
2662
|
+
targetType,
|
|
2663
|
+
]);
|
|
2664
|
+
else if (constraint !== undefined && isTypeAssignableTo(c, generalizedSource, constraint))
|
|
2665
|
+
this.reportError(1157 /* Diagnostics.X_0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2 */, [generalizedSourceType, targetType, typeToString(c, constraint)]);
|
|
2597
2666
|
else if (constraint !== undefined && isTypeAssignableTo(c, source, constraint))
|
|
2598
|
-
this.reportError(
|
|
2667
|
+
this.reportError(1157 /* Diagnostics.X_0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2 */, [sourceType, targetType, typeToString(c, constraint)]);
|
|
2599
2668
|
else {
|
|
2600
2669
|
// Reported once.
|
|
2601
2670
|
this.errorChain = undefined;
|
|
2602
|
-
this.reportError(
|
|
2671
|
+
this.reportError(1164 /* Diagnostics.X_0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1 */, [
|
|
2603
2672
|
targetType,
|
|
2604
2673
|
generalizedSourceType,
|
|
2605
2674
|
]);
|
|
@@ -2607,18 +2676,18 @@ export class Relater extends TypeComparer {
|
|
|
2607
2676
|
}
|
|
2608
2677
|
if (message === undefined) {
|
|
2609
2678
|
if (this.relation === c.comparableRelation)
|
|
2610
|
-
message =
|
|
2679
|
+
message = 819 /* Diagnostics.Type_0_is_not_comparable_to_type_1 */;
|
|
2611
2680
|
else if (sourceType === targetType)
|
|
2612
2681
|
message =
|
|
2613
|
-
|
|
2682
|
+
858 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated */;
|
|
2614
2683
|
else if (c.exactOptionalPropertyTypes && getExactOptionalUnassignableProperties(c, source, target).length !== 0)
|
|
2615
2684
|
message =
|
|
2616
|
-
|
|
2685
|
+
556 /* Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties */;
|
|
2617
2686
|
else {
|
|
2618
2687
|
if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
|
|
2619
2688
|
const suggested = getSuggestedTypeForNonexistentStringLiteralType(c, source, target);
|
|
2620
2689
|
if (suggested !== undefined) {
|
|
2621
|
-
this.reportError(
|
|
2690
|
+
this.reportError(958 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Did_you_mean_2 */, [
|
|
2622
2691
|
generalizedSourceType,
|
|
2623
2692
|
targetType,
|
|
2624
2693
|
typeToString(c, suggested),
|
|
@@ -2626,32 +2695,31 @@ export class Relater extends TypeComparer {
|
|
|
2626
2695
|
return;
|
|
2627
2696
|
}
|
|
2628
2697
|
}
|
|
2629
|
-
message =
|
|
2698
|
+
message = 507 /* Diagnostics.Type_0_is_not_assignable_to_type_1 */;
|
|
2630
2699
|
}
|
|
2631
2700
|
}
|
|
2632
|
-
else if (message ===
|
|
2701
|
+
else if (message === 528 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 */ &&
|
|
2633
2702
|
c.exactOptionalPropertyTypes &&
|
|
2634
2703
|
getExactOptionalUnassignableProperties(c, source, target).length !== 0)
|
|
2635
2704
|
message =
|
|
2636
|
-
|
|
2705
|
+
560 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties */;
|
|
2637
2706
|
switch (this.getChainMessage(0)) {
|
|
2638
2707
|
// Suppressed after an excess property error.
|
|
2639
|
-
case
|
|
2640
|
-
case
|
|
2708
|
+
case 536 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */:
|
|
2709
|
+
case 722 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */:
|
|
2641
2710
|
return;
|
|
2642
|
-
case
|
|
2643
|
-
case
|
|
2644
|
-
case 1090 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */:
|
|
2711
|
+
case 986 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */:
|
|
2712
|
+
case 1097 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */:
|
|
2645
2713
|
if (this.chainArgsMatch(generalizedSourceType, targetType, undefined))
|
|
2646
2714
|
return;
|
|
2647
2715
|
break;
|
|
2648
|
-
case
|
|
2716
|
+
case 880 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */:
|
|
2649
2717
|
if (!isConversionOrInterfaceImplementationMessage(message) &&
|
|
2650
2718
|
this.chainArgsMatch(undefined, generalizedSourceType, targetType))
|
|
2651
2719
|
return;
|
|
2652
2720
|
break;
|
|
2653
|
-
case
|
|
2654
|
-
case
|
|
2721
|
+
case 879 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more */:
|
|
2722
|
+
case 878 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2 */:
|
|
2655
2723
|
if (!isConversionOrInterfaceImplementationMessage(message) &&
|
|
2656
2724
|
this.chainArgsMatch(generalizedSourceType, targetType, undefined))
|
|
2657
2725
|
return;
|
|
@@ -2660,44 +2728,44 @@ export class Relater extends TypeComparer {
|
|
|
2660
2728
|
this.reportError(message, [generalizedSourceType, targetType]);
|
|
2661
2729
|
}
|
|
2662
2730
|
reportError(message, args) {
|
|
2663
|
-
if (message ===
|
|
2731
|
+
if (message === 511 /* Diagnostics.Types_of_property_0_are_incompatible */) {
|
|
2664
2732
|
switch (this.getChainMessage(0)) {
|
|
2665
|
-
case
|
|
2666
|
-
case
|
|
2733
|
+
case 536 /* Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1 */:
|
|
2734
|
+
case 722 /* Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2 */:
|
|
2667
2735
|
return;
|
|
2668
2736
|
}
|
|
2669
2737
|
// A property followed by a return type incompatibility becomes one message for `x()`.
|
|
2670
2738
|
let arg = '';
|
|
2671
2739
|
switch (this.getChainMessage(1)) {
|
|
2672
|
-
case
|
|
2740
|
+
case 476 /* Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
|
|
2673
2741
|
arg = getPropertyNameArg(args[0]) + '()';
|
|
2674
2742
|
break;
|
|
2675
|
-
case
|
|
2743
|
+
case 477 /* Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
|
|
2676
2744
|
arg = 'new ' + getPropertyNameArg(args[0]) + '()';
|
|
2677
2745
|
break;
|
|
2678
|
-
case
|
|
2746
|
+
case 474 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */:
|
|
2679
2747
|
arg = getPropertyNameArg(args[0]) + '(...)';
|
|
2680
2748
|
break;
|
|
2681
|
-
case
|
|
2749
|
+
case 475 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */:
|
|
2682
2750
|
arg = 'new ' + getPropertyNameArg(args[0]) + '(...)';
|
|
2683
2751
|
break;
|
|
2684
2752
|
}
|
|
2685
2753
|
if (arg !== '') {
|
|
2686
|
-
message =
|
|
2754
|
+
message = 473 /* Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types */;
|
|
2687
2755
|
args = [arg];
|
|
2688
2756
|
this.errorChain = this.errorChain.next.next;
|
|
2689
2757
|
}
|
|
2690
2758
|
// Nested property incompatibilities become one message for `x.y`.
|
|
2691
2759
|
switch (this.getChainMessage(1)) {
|
|
2692
|
-
case
|
|
2693
|
-
case
|
|
2694
|
-
case
|
|
2760
|
+
case 511 /* Diagnostics.Types_of_property_0_are_incompatible */:
|
|
2761
|
+
case 472 /* Diagnostics.The_types_of_0_are_incompatible_between_these_types */:
|
|
2762
|
+
case 473 /* Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types */: {
|
|
2695
2763
|
const head = getPropertyNameArg(args[0]);
|
|
2696
2764
|
const tail = getPropertyNameArg(this.errorChain.next.args[0]);
|
|
2697
2765
|
const dotted = addToDottedName(head, tail);
|
|
2698
2766
|
this.errorChain = this.errorChain.next.next;
|
|
2699
|
-
if (message ===
|
|
2700
|
-
message =
|
|
2767
|
+
if (message === 511 /* Diagnostics.Types_of_property_0_are_incompatible */)
|
|
2768
|
+
message = 472 /* Diagnostics.The_types_of_0_are_incompatible_between_these_types */;
|
|
2701
2769
|
this.reportError(message, [dotted]);
|
|
2702
2770
|
return;
|
|
2703
2771
|
}
|
|
@@ -2775,7 +2843,7 @@ export function getSingleBaseForNonAugmentingSubtype(c, t) {
|
|
|
2775
2843
|
const baseTypeNode = declaration !== undefined ? getExtendsHeritageClauseElement(declaration) : undefined;
|
|
2776
2844
|
if (baseTypeNode !== undefined) {
|
|
2777
2845
|
const expression = getExpression(baseTypeNode);
|
|
2778
|
-
if (expression.kind !== 79 /* SyntaxKind.Identifier */ && expression.kind !==
|
|
2846
|
+
if (expression.kind !== 79 /* SyntaxKind.Identifier */ && expression.kind !== 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
2779
2847
|
return undefined;
|
|
2780
2848
|
}
|
|
2781
2849
|
}
|
|
@@ -2912,12 +2980,12 @@ function isIgnoredJsxProperty(source, prop) {
|
|
|
2912
2980
|
}
|
|
2913
2981
|
function isObjectLiteralElement(node) {
|
|
2914
2982
|
switch (node.kind) {
|
|
2915
|
-
case
|
|
2916
|
-
case
|
|
2917
|
-
case
|
|
2918
|
-
case
|
|
2919
|
-
case
|
|
2920
|
-
case
|
|
2983
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
2984
|
+
case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
2985
|
+
case 306 /* SyntaxKind.SpreadAssignment */:
|
|
2986
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
2987
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
2988
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
2921
2989
|
return true;
|
|
2922
2990
|
}
|
|
2923
2991
|
return false;
|
|
@@ -3045,13 +3113,13 @@ export function isDiscriminantProperty(c, t, name) {
|
|
|
3045
3113
|
const prop = getUnionOrIntersectionProperty(c, t, name, false);
|
|
3046
3114
|
if (prop === undefined || (prop.checkFlags & 2 /* CheckFlags.SyntheticProperty */) === 0)
|
|
3047
3115
|
return false;
|
|
3048
|
-
if ((prop.checkFlags &
|
|
3049
|
-
prop.checkFlags |=
|
|
3116
|
+
if ((prop.checkFlags & 16777216 /* CheckFlags.IsDiscriminantComputed */) === 0) {
|
|
3117
|
+
prop.checkFlags |= 16777216 /* CheckFlags.IsDiscriminantComputed */;
|
|
3050
3118
|
if ((prop.checkFlags & 192 /* CheckFlags.NonUniformAndLiteral */) === 192 /* CheckFlags.NonUniformAndLiteral */ &&
|
|
3051
3119
|
!isGenericTypeLocal(c, getTypeOfSymbol(c, prop)))
|
|
3052
|
-
prop.checkFlags |=
|
|
3120
|
+
prop.checkFlags |= 33554432 /* CheckFlags.IsDiscriminant */;
|
|
3053
3121
|
}
|
|
3054
|
-
return (prop.checkFlags &
|
|
3122
|
+
return (prop.checkFlags & 33554432 /* CheckFlags.IsDiscriminant */) !== 0;
|
|
3055
3123
|
}
|
|
3056
3124
|
import { isGenericType as isGenericTypeLocal } from './checker-type-operators.js';
|
|
3057
3125
|
/** The constituent selected by a key property's unit type; not computed yet. */
|
|
@@ -3269,14 +3337,14 @@ function contextFreeExpressionDeclaration(c, t) {
|
|
|
3269
3337
|
if (declaration === undefined)
|
|
3270
3338
|
return undefined;
|
|
3271
3339
|
switch (declaration.kind) {
|
|
3272
|
-
case
|
|
3273
|
-
case
|
|
3274
|
-
case
|
|
3275
|
-
case
|
|
3276
|
-
case
|
|
3277
|
-
case
|
|
3278
|
-
case
|
|
3279
|
-
case
|
|
3340
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
3341
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
3342
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
3343
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
3344
|
+
case 228 /* SyntaxKind.BinaryExpression */:
|
|
3345
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
3346
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
3347
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
3280
3348
|
return isContextSensitive(c, declaration) ? undefined : declaration;
|
|
3281
3349
|
}
|
|
3282
3350
|
return undefined;
|
|
@@ -3314,14 +3382,14 @@ export function setStackEntry(stack, depth, t) {
|
|
|
3314
3382
|
export function isDeeplyNestedType(c, t, stack, depth, maxDepth) {
|
|
3315
3383
|
if (depth < maxDepth)
|
|
3316
3384
|
return false;
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
|
|
3321
|
-
for (const u of typesOf(t))
|
|
3385
|
+
const target = getRecursionIdentityTarget(c, t);
|
|
3386
|
+
if ((target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
3387
|
+
for (const u of typesOf(target))
|
|
3322
3388
|
if (isDeeplyNestedType(c, u, stack, depth, maxDepth))
|
|
3323
3389
|
return true;
|
|
3324
|
-
|
|
3390
|
+
return false;
|
|
3391
|
+
}
|
|
3392
|
+
const identity = getRecursionIdentityFromTarget(target);
|
|
3325
3393
|
let count = 0;
|
|
3326
3394
|
let lastTypeId = 0;
|
|
3327
3395
|
for (let i = 0; i < depth; i++) {
|
|
@@ -3337,8 +3405,64 @@ export function isDeeplyNestedType(c, t, stack, depth, maxDepth) {
|
|
|
3337
3405
|
}
|
|
3338
3406
|
return false;
|
|
3339
3407
|
}
|
|
3340
|
-
|
|
3408
|
+
/**
|
|
3409
|
+
* isDeeplyNestedType for the newest entry of `stack[start..end)`, counting only the entries in that range.
|
|
3410
|
+
* `identities` holds the recursion identity of each entry of the range once a check has computed it: 0 before
|
|
3411
|
+
* that, and -1 for an entry whose recursion identity target is an intersection, which is matched by its
|
|
3412
|
+
* constituents each time. Later checks compare the kept identities. The identities are computed when and in the
|
|
3413
|
+
* order isDeeplyNestedType computes them, so the types and symbol ids they create come in the same order.
|
|
3414
|
+
*/
|
|
3415
|
+
export function isDeeplyNestedStackEntry(c, stack, identities, start, end, maxDepth) {
|
|
3416
|
+
if (end - start < maxDepth)
|
|
3417
|
+
return false;
|
|
3418
|
+
return isDeeplyNestedInRange(c, stack[end - 1], true, stack, identities, start, end, maxDepth);
|
|
3419
|
+
}
|
|
3420
|
+
function isDeeplyNestedInRange(c, t, isEntry, stack, identities, start, end, maxDepth) {
|
|
3421
|
+
const target = getRecursionIdentityTarget(c, t);
|
|
3422
|
+
if ((target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
3423
|
+
if (isEntry)
|
|
3424
|
+
identities[end - 1] = -1;
|
|
3425
|
+
for (const u of typesOf(target))
|
|
3426
|
+
if (isDeeplyNestedInRange(c, u, false, stack, identities, start, end, maxDepth))
|
|
3427
|
+
return true;
|
|
3428
|
+
return false;
|
|
3429
|
+
}
|
|
3430
|
+
const identity = getRecursionIdentityFromTarget(target);
|
|
3431
|
+
if (isEntry)
|
|
3432
|
+
identities[end - 1] = identity;
|
|
3433
|
+
let count = 0;
|
|
3434
|
+
let lastTypeId = 0;
|
|
3435
|
+
for (let i = start; i < end; i++) {
|
|
3436
|
+
const s = stack[i];
|
|
3437
|
+
let known = identities[i];
|
|
3438
|
+
if (known === 0) {
|
|
3439
|
+
const sourceTarget = getRecursionIdentityTarget(c, s);
|
|
3440
|
+
known = (sourceTarget.flags & 268435456 /* TypeFlags.Intersection */) !== 0 ? -1 : getRecursionIdentityFromTarget(sourceTarget);
|
|
3441
|
+
identities[i] = known;
|
|
3442
|
+
}
|
|
3443
|
+
if (known >= 0 ? known === identity : hasMatchingRecursionIdentity(c, s, identity)) {
|
|
3444
|
+
if (s.id >= lastTypeId) {
|
|
3445
|
+
count++;
|
|
3446
|
+
if (count >= maxDepth)
|
|
3447
|
+
return true;
|
|
3448
|
+
}
|
|
3449
|
+
lastTypeId = s.id;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
return false;
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* The type whose recursion identity `t` has: the object type of an indexed access (T in T[K]), and for a
|
|
3456
|
+
* homomorphic mapped type the deepest target type that has a symbol. Unwrapping mapped types keeps the identities of
|
|
3457
|
+
* mapped types applied to written object literals unique: in `Mapped<{ x: Mapped<{ x: Mapped<{ x: string }>}>}>`,
|
|
3458
|
+
* each application has the identity of its object literal and does not appear deeply nested.
|
|
3459
|
+
*/
|
|
3460
|
+
function getRecursionIdentityTarget(c, t) {
|
|
3341
3461
|
for (;;) {
|
|
3462
|
+
if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
|
|
3463
|
+
t = t.objectType;
|
|
3464
|
+
continue;
|
|
3465
|
+
}
|
|
3342
3466
|
if ((t.objectFlags & 96 /* ObjectFlags.InstantiatedMapped */) === 96 /* ObjectFlags.InstantiatedMapped */ &&
|
|
3343
3467
|
(t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
3344
3468
|
const target = getModifiersTypeFromMappedType(c, t);
|
|
@@ -3352,38 +3476,33 @@ function getMappedTargetWithSymbol(c, t) {
|
|
|
3352
3476
|
}
|
|
3353
3477
|
}
|
|
3354
3478
|
function hasMatchingRecursionIdentity(c, t, identity) {
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
3359
|
-
for (const u of typesOf(t))
|
|
3479
|
+
const target = getRecursionIdentityTarget(c, t);
|
|
3480
|
+
if ((target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
3481
|
+
for (const u of typesOf(target))
|
|
3360
3482
|
if (hasMatchingRecursionIdentity(c, u, identity))
|
|
3361
3483
|
return true;
|
|
3362
3484
|
return false;
|
|
3363
3485
|
}
|
|
3364
|
-
return
|
|
3486
|
+
return getRecursionIdentityFromTarget(target) === identity;
|
|
3365
3487
|
}
|
|
3366
3488
|
/** An identity shared by instantiations of a type, so infinitely expanding instantiations can be detected. */
|
|
3367
|
-
export function getRecursionIdentity(t) {
|
|
3489
|
+
export function getRecursionIdentity(c, t) {
|
|
3490
|
+
return getRecursionIdentityFromTarget(getRecursionIdentityTarget(c, t));
|
|
3491
|
+
}
|
|
3492
|
+
function getRecursionIdentityFromTarget(t) {
|
|
3368
3493
|
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
|
|
3369
3494
|
(t.objectFlags & (128 /* ObjectFlags.ObjectLiteral */ | 16384 /* ObjectFlags.ArrayLiteral */)) === 0) {
|
|
3370
3495
|
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && t.node !== undefined)
|
|
3371
3496
|
return nodeRecursionId(t.node);
|
|
3372
3497
|
if (t.symbol !== undefined &&
|
|
3373
3498
|
!((t.objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0 && (t.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) &&
|
|
3374
|
-
(t.objectFlags &
|
|
3499
|
+
(t.objectFlags & 536870912 /* ObjectFlags.FromTypeNode */) === 0)
|
|
3375
3500
|
return symbolRecursionId(t.symbol);
|
|
3376
|
-
if (isTupleType(t) && (t.objectFlags &
|
|
3501
|
+
if (isTupleType(t) && (t.objectFlags & 536870912 /* ObjectFlags.FromTypeNode */) === 0)
|
|
3377
3502
|
return typeRecursionId(t.target);
|
|
3378
3503
|
}
|
|
3379
3504
|
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && t.symbol !== undefined)
|
|
3380
3505
|
return symbolRecursionId(t.symbol);
|
|
3381
|
-
if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
|
|
3382
|
-
let objectType = t.objectType;
|
|
3383
|
-
while ((objectType.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0)
|
|
3384
|
-
objectType = objectType.objectType;
|
|
3385
|
-
return typeRecursionId(objectType);
|
|
3386
|
-
}
|
|
3387
3506
|
if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
|
|
3388
3507
|
return nodeRecursionId(t.root.node);
|
|
3389
3508
|
return typeRecursionId(t);
|
|
@@ -3414,17 +3533,50 @@ export function getAliasVariances(c, symbol) {
|
|
|
3414
3533
|
* The measured variance of each type parameter, from relating marker instantiations; empty when
|
|
3415
3534
|
* requested recursively.
|
|
3416
3535
|
*/
|
|
3536
|
+
/** A generic type whose variances are being computed. */
|
|
3537
|
+
export class VarianceStackEntry {
|
|
3538
|
+
symbol;
|
|
3539
|
+
typeParameters;
|
|
3540
|
+
constructor(symbol, typeParameters) {
|
|
3541
|
+
this.symbol = symbol;
|
|
3542
|
+
this.typeParameters = typeParameters;
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3417
3545
|
function getVariancesWorker(c, symbol, typeParameters) {
|
|
3418
3546
|
const links = c.symbolLinks(symbol);
|
|
3419
3547
|
if (links.variances !== undefined)
|
|
3420
3548
|
return links.variances;
|
|
3421
|
-
|
|
3549
|
+
let stackIndex = -1;
|
|
3550
|
+
for (let i = 0; i < c.varianceStack.length; i++)
|
|
3551
|
+
if (c.varianceStack[i].symbol === symbol) {
|
|
3552
|
+
stackIndex = i;
|
|
3553
|
+
break;
|
|
3554
|
+
}
|
|
3555
|
+
if (stackIndex >= 0) {
|
|
3556
|
+
// A circularity. The variances computed can depend on where the circular region is entered, so the
|
|
3557
|
+
// computation restarts from the generic type with the smallest symbol in the region if that is not this one,
|
|
3558
|
+
// which keeps the results of circular generic types stable.
|
|
3559
|
+
let minIndex = stackIndex;
|
|
3560
|
+
for (let i = stackIndex + 1; i < c.varianceStack.length; i++)
|
|
3561
|
+
if (compareSymbols(c, c.varianceStack[i].symbol, c.varianceStack[minIndex].symbol) < 0)
|
|
3562
|
+
minIndex = i;
|
|
3563
|
+
if (minIndex > stackIndex) {
|
|
3564
|
+
const saveVarianceStack = c.varianceStack;
|
|
3565
|
+
c.varianceStack = [];
|
|
3566
|
+
getVariancesWorker(c, saveVarianceStack[minIndex].symbol, saveVarianceStack[minIndex].typeParameters);
|
|
3567
|
+
c.varianceStack = saveVarianceStack;
|
|
3568
|
+
}
|
|
3569
|
+
// Variances that cannot be computed: the type parameters are treated as covariant. The computation in
|
|
3570
|
+
// progress stores its results over this.
|
|
3571
|
+
const stored = storedVariances(links);
|
|
3572
|
+
if (stored === undefined || stored.length === 0)
|
|
3573
|
+
links.variances = [];
|
|
3574
|
+
return links.variances;
|
|
3575
|
+
}
|
|
3422
3576
|
const saveResolutionStart = c.resolutionStart;
|
|
3423
|
-
if (
|
|
3424
|
-
c.inVarianceComputation = true;
|
|
3577
|
+
if (c.varianceStack.length === 0)
|
|
3425
3578
|
c.resolutionStart = c.resolutionDepth;
|
|
3426
|
-
|
|
3427
|
-
links.variances = [];
|
|
3579
|
+
c.varianceStack.push(new VarianceStackEntry(symbol, typeParameters));
|
|
3428
3580
|
const variances = [];
|
|
3429
3581
|
for (const tp of typeParameters) {
|
|
3430
3582
|
const modifiers = getTypeParameterModifiers(tp);
|
|
@@ -3451,14 +3603,24 @@ function getVariancesWorker(c, symbol, typeParameters) {
|
|
|
3451
3603
|
variance |= 16 /* VarianceFlags.Unreliable */;
|
|
3452
3604
|
c.reliabilityFlags = saveReliabilityFlags;
|
|
3453
3605
|
}
|
|
3606
|
+
// A computation restarted because of a circularity may have stored the variances already.
|
|
3607
|
+
const restarted = storedVariances(links);
|
|
3608
|
+
if (restarted !== undefined && restarted.length !== 0)
|
|
3609
|
+
break;
|
|
3454
3610
|
variances.push(variance);
|
|
3455
3611
|
}
|
|
3456
|
-
|
|
3457
|
-
|
|
3612
|
+
// Unless a restarted computation stored them.
|
|
3613
|
+
const stored = storedVariances(links);
|
|
3614
|
+
if (stored === undefined || stored.length === 0)
|
|
3615
|
+
links.variances = variances;
|
|
3616
|
+
c.varianceStack.pop();
|
|
3617
|
+
if (c.varianceStack.length === 0)
|
|
3458
3618
|
c.resolutionStart = saveResolutionStart;
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3619
|
+
return links.variances;
|
|
3620
|
+
}
|
|
3621
|
+
/** The variances stored in `links`, read again after computations that may have stored them. */
|
|
3622
|
+
function storedVariances(links) {
|
|
3623
|
+
return links.variances;
|
|
3462
3624
|
}
|
|
3463
3625
|
export function createMarkerType(c, symbol, source, target) {
|
|
3464
3626
|
const mapper = new SimpleTypeMapper(source, target);
|
|
@@ -3658,7 +3820,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3658
3820
|
: getMinArgumentCount(c, source) > targetCount);
|
|
3659
3821
|
if (sourceHasMoreParameters) {
|
|
3660
3822
|
if (reportErrors && (checkMode & 8 /* SignatureCheckMode.StrictArity */) === 0)
|
|
3661
|
-
comparer.report(
|
|
3823
|
+
comparer.report(976 /* Diagnostics.Target_signature_provides_too_few_arguments_Expected_0_or_more_but_got_1 */, [
|
|
3662
3824
|
String(getMinArgumentCount(c, source)),
|
|
3663
3825
|
String(targetCount),
|
|
3664
3826
|
]);
|
|
@@ -3676,9 +3838,9 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3676
3838
|
const kind = target.declaration !== undefined ? target.declaration.kind : 0 /* SyntaxKind.Unknown */;
|
|
3677
3839
|
const strictVariance = (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 &&
|
|
3678
3840
|
c.strictFunctionTypes &&
|
|
3679
|
-
kind !==
|
|
3680
|
-
kind !==
|
|
3681
|
-
kind !==
|
|
3841
|
+
kind !== 176 /* SyntaxKind.MethodDeclaration */ &&
|
|
3842
|
+
kind !== 175 /* SyntaxKind.MethodSignature */ &&
|
|
3843
|
+
kind !== 178 /* SyntaxKind.Constructor */;
|
|
3682
3844
|
let result = -1 /* Ternary.True */;
|
|
3683
3845
|
const sourceThisType = getThisTypeOfSignature(c, source);
|
|
3684
3846
|
if (sourceThisType !== undefined && sourceThisType !== c.voidType) {
|
|
@@ -3690,7 +3852,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3690
3852
|
related = comparer.compare(targetThisType, sourceThisType, reportErrors);
|
|
3691
3853
|
if (related === 0 /* Ternary.False */) {
|
|
3692
3854
|
if (reportErrors)
|
|
3693
|
-
comparer.report(
|
|
3855
|
+
comparer.report(825 /* Diagnostics.The_this_types_of_each_signature_are_incompatible */, []);
|
|
3694
3856
|
return 0 /* Ternary.False */;
|
|
3695
3857
|
}
|
|
3696
3858
|
result &= related;
|
|
@@ -3740,7 +3902,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3740
3902
|
related = 0 /* Ternary.False */;
|
|
3741
3903
|
if (related === 0 /* Ternary.False */) {
|
|
3742
3904
|
if (reportErrors)
|
|
3743
|
-
comparer.report(
|
|
3905
|
+
comparer.report(513 /* Diagnostics.Types_of_parameters_0_and_1_are_incompatible */, [
|
|
3744
3906
|
getParameterNameAtPosition(c, source, i),
|
|
3745
3907
|
getParameterNameAtPosition(c, target, i),
|
|
3746
3908
|
]);
|
|
@@ -3779,11 +3941,11 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3779
3941
|
const construct = (source.flags & 4 /* SignatureFlags.Construct */) !== 0;
|
|
3780
3942
|
const message = source.parameters.length === 0 && target.parameters.length === 0
|
|
3781
3943
|
? construct
|
|
3782
|
-
?
|
|
3783
|
-
:
|
|
3944
|
+
? 477 /* Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */
|
|
3945
|
+
: 476 /* Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */
|
|
3784
3946
|
: construct
|
|
3785
|
-
?
|
|
3786
|
-
:
|
|
3947
|
+
? 475 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */
|
|
3948
|
+
: 474 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */;
|
|
3787
3949
|
comparer.report(message, [typeToString(c, sourceReturnType), typeToString(c, targetReturnType)]);
|
|
3788
3950
|
}
|
|
3789
3951
|
}
|
|
@@ -3799,7 +3961,7 @@ function isInstantiatedGenericParameter(c, signature, pos) {
|
|
|
3799
3961
|
function compareTypePredicateRelatedTo(c, source, target, reportErrors, comparer) {
|
|
3800
3962
|
if (source.kind !== target.kind) {
|
|
3801
3963
|
if (reportErrors) {
|
|
3802
|
-
comparer.report(
|
|
3964
|
+
comparer.report(685 /* Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard */, []);
|
|
3803
3965
|
comparer.report(176 /* Diagnostics.Type_predicate_0_is_not_assignable_to_1 */, [
|
|
3804
3966
|
typePredicateToString(c, source),
|
|
3805
3967
|
typePredicateToString(c, target),
|
|
@@ -3976,6 +4138,7 @@ export function isExactOptionalPropertyMismatch(c, source, target) {
|
|
|
3976
4138
|
containsMissingType(c, target));
|
|
3977
4139
|
}
|
|
3978
4140
|
/** The string literal member of `target` closest to the string literal `source`. */
|
|
4141
|
+
const maxStringLiteralSuggestionCandidates = 1000;
|
|
3979
4142
|
function getSuggestedTypeForNonexistentStringLiteralType(c, source, target) {
|
|
3980
4143
|
const value = source.stringValue;
|
|
3981
4144
|
const valueCodePoints = new CodePoints();
|
|
@@ -3984,9 +4147,13 @@ function getSuggestedTypeForNonexistentStringLiteralType(c, source, target) {
|
|
|
3984
4147
|
let bestDistance = Math.floor(valueCodePoints.length * 0.4) + 0.9;
|
|
3985
4148
|
let best = undefined;
|
|
3986
4149
|
const lowerValue = value.toLowerCase();
|
|
4150
|
+
// A target with more string literal candidates than this gets no suggestion.
|
|
4151
|
+
let candidates = 0;
|
|
3987
4152
|
for (const t of typesOf(target)) {
|
|
3988
4153
|
if ((t.flags & 1024 /* TypeFlags.StringLiteral */) === 0)
|
|
3989
4154
|
continue;
|
|
4155
|
+
if (++candidates > maxStringLiteralSuggestionCandidates)
|
|
4156
|
+
return undefined;
|
|
3990
4157
|
const name = t.stringValue;
|
|
3991
4158
|
const nameLength = utf8Length(name);
|
|
3992
4159
|
if (name === '' || Math.abs(nameLength - valueCodePoints.length) > maximumLengthDifference || name === value)
|