tsc-ts 0.0.10 → 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 +1 -1
- 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 +20 -15
- package/dist/api/compiler/ast.js +1023 -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 +173 -123
- 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 +469 -438
- 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 -113
- 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 +210 -74
- 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 +137 -34
- 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 +93 -31
- package/dist/api/compiler/checker.js +143 -35
- 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 +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- 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 +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- 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/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 +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -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 +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -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 +2 -0
- package/dist/api/compiler/program.js +69 -57
- 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 +337 -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 +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- 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 +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- 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 +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- 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 +197 -55
- 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 +120 -21
- 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 +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- 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 +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- 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 +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -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 +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -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 +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- 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 +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- 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
|
}
|
|
@@ -433,15 +456,15 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
433
456
|
const targetProperty = getPropertyOfType(c, targetEnumType, sourceProperty.name);
|
|
434
457
|
if (targetProperty === undefined || (targetProperty.flags & 8 /* SymbolFlags.EnumMember */) === 0) {
|
|
435
458
|
if (reporter !== undefined)
|
|
436
|
-
reporter.reportError(
|
|
459
|
+
reporter.reportError(509 /* Diagnostics.Property_0_is_missing_in_type_1 */, [
|
|
437
460
|
symbolToString(c, sourceProperty),
|
|
438
461
|
typeToString(c, getDeclaredTypeOfSymbol(c, targetSymbol), undefined, 1 << 6),
|
|
439
462
|
]);
|
|
440
463
|
c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
|
|
441
464
|
return false;
|
|
442
465
|
}
|
|
443
|
-
const sourceDecl = getDeclarations(sourceProperty).find((d) => d.kind ===
|
|
444
|
-
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 */);
|
|
445
468
|
if (sourceDecl === undefined || targetDecl === undefined)
|
|
446
469
|
continue;
|
|
447
470
|
computeEnumMemberValues(c, sourceDecl.parent);
|
|
@@ -455,7 +478,7 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
455
478
|
continue;
|
|
456
479
|
if (s.enumValueKind !== 0 && t.enumValueKind !== 0) {
|
|
457
480
|
if (reporter !== undefined)
|
|
458
|
-
reporter.reportError(
|
|
481
|
+
reporter.reportError(1118 /* Diagnostics.Each_declaration_of_0_1_differs_in_its_value_where_2_was_expected_but_3_was_given */, [
|
|
459
482
|
symbolToString(c, targetSymbol),
|
|
460
483
|
symbolToString(c, targetProperty),
|
|
461
484
|
enumValueText(t.enumValueKind, t.enumNumberValue, t.enumStringValue),
|
|
@@ -468,7 +491,7 @@ function isEnumTypeRelatedTo(c, source, target, reporter) {
|
|
|
468
491
|
if (s.enumValueKind === 2 || t.enumValueKind === 2) {
|
|
469
492
|
if (reporter !== undefined) {
|
|
470
493
|
const known = s.enumValueKind === 2 ? s : t;
|
|
471
|
-
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)]);
|
|
472
495
|
}
|
|
473
496
|
c.enumRelation.set(key, 2 /* RelationComparisonResult.Failed */);
|
|
474
497
|
return false;
|
|
@@ -623,20 +646,35 @@ export function checkTypeRelatedTo(c, source, target, relation, errorNode, headM
|
|
|
623
646
|
// Nested checks (from resolving types during the relation) find no spare and allocate their own.
|
|
624
647
|
const r = c.spareRelater ?? new Relater(c, relation, errorNode);
|
|
625
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
|
+
}
|
|
626
667
|
r.reset(relation, errorNode);
|
|
627
|
-
r.relationCount =
|
|
668
|
+
r.relationCount = relationCount;
|
|
628
669
|
const result = r.isRelatedToEx(source, target, 3 /* RecursionFlags.Both */, errorNode !== undefined, headMessage, 0 /* IntersectionState.None */);
|
|
629
670
|
if (r.overflow) {
|
|
630
671
|
// Remember the overflow so it isn't attempted again.
|
|
631
672
|
const key = getRelationKey(c, source, target, 0 /* IntersectionState.None */, relation === c.identityRelation, false).key;
|
|
632
|
-
relation.set(key, 2 /* RelationComparisonResult.Failed */ |
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
? 979 /* Diagnostics.Excessive_complexity_comparing_types_0_and_1 */
|
|
638
|
-
: 499 /* Diagnostics.Excessive_stack_depth_comparing_types_0_and_1 */;
|
|
639
|
-
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);
|
|
640
678
|
}
|
|
641
679
|
else if (r.errorChain !== undefined) {
|
|
642
680
|
const diagnostic = createDiagnosticFromErrorChain(r.errorChain, r.errorNode, r.relatedInfo);
|
|
@@ -719,14 +757,14 @@ function addToDottedName(head, tail) {
|
|
|
719
757
|
return suffix.startsWith('[') ? prefix + head + suffix : prefix + head + '.' + suffix;
|
|
720
758
|
}
|
|
721
759
|
function isConversionOrInterfaceImplementationMessage(message) {
|
|
722
|
-
return (message ===
|
|
760
|
+
return (message === 598 /* Diagnostics.Class_0_incorrectly_implements_interface_1 */ ||
|
|
723
761
|
message ===
|
|
724
|
-
|
|
762
|
+
859 /* Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass */ ||
|
|
725
763
|
message ===
|
|
726
|
-
|
|
727
|
-
message ===
|
|
728
|
-
message ===
|
|
729
|
-
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 */);
|
|
730
768
|
}
|
|
731
769
|
// ---- The relater
|
|
732
770
|
/** The state of a relation check: its error chain, maybe-stack and recursion stacks. */
|
|
@@ -746,6 +784,8 @@ export class Relater extends TypeComparer {
|
|
|
746
784
|
expandingFlags = 0 /* ExpandingFlags.None */;
|
|
747
785
|
overflow = false;
|
|
748
786
|
relationCount = 0;
|
|
787
|
+
/** The keys this check added to the relation, while relating without reporting first. */
|
|
788
|
+
addedKeys = undefined;
|
|
749
789
|
/** The intersection state passed to `compare` during signature comparisons. */
|
|
750
790
|
signatureIntersectionState = 0 /* IntersectionState.None */;
|
|
751
791
|
// What `relateVariances` changes in its caller's state when it falls back to structure.
|
|
@@ -868,9 +908,9 @@ export class Relater extends TypeComparer {
|
|
|
868
908
|
(constructs.length > 0 &&
|
|
869
909
|
this.isRelatedTo(getReturnTypeOfSignature(c, constructs[0]), target, 1 /* RecursionFlags.Source */, false) !==
|
|
870
910
|
0 /* Ternary.False */))
|
|
871
|
-
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]);
|
|
872
912
|
else
|
|
873
|
-
this.reportError(
|
|
913
|
+
this.reportError(720 /* Diagnostics.Type_0_has_no_properties_in_common_with_type_1 */, [sourceString, targetString]);
|
|
874
914
|
}
|
|
875
915
|
return 0 /* Ternary.False */;
|
|
876
916
|
}
|
|
@@ -919,25 +959,25 @@ export class Relater extends TypeComparer {
|
|
|
919
959
|
// Report in terms of the object types we check in isKnownProperty, at the property.
|
|
920
960
|
const errorTarget = filterType(c, reducedTarget, isExcessPropertyCheckTarget);
|
|
921
961
|
const errorNode = this.errorNode;
|
|
922
|
-
if (errorNode.kind ===
|
|
962
|
+
if (errorNode.kind === 294 /* SyntaxKind.JsxAttributes */ ||
|
|
923
963
|
isJsxOpeningLikeElement(errorNode) ||
|
|
924
964
|
(errorNode.parent !== undefined && isJsxOpeningLikeElement(errorNode.parent))) {
|
|
925
965
|
// Attributes are checked like object literals but reported as attributes, at the attribute.
|
|
926
966
|
const valueDeclaration = prop.valueDeclaration;
|
|
927
967
|
if (valueDeclaration !== undefined &&
|
|
928
|
-
valueDeclaration.kind ===
|
|
968
|
+
valueDeclaration.kind === 293 /* SyntaxKind.JsxAttribute */ &&
|
|
929
969
|
sameFile(valueDeclaration, errorNode))
|
|
930
970
|
this.errorNode = getName(valueDeclaration);
|
|
931
971
|
const propName = symbolToString(c, prop);
|
|
932
972
|
const suggestion = getSuggestedSymbolForNonexistentJSXAttribute(c, propName, errorTarget);
|
|
933
973
|
if (suggestion !== undefined)
|
|
934
|
-
this.reportError(
|
|
974
|
+
this.reportError(713 /* Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2 */, [
|
|
935
975
|
propName,
|
|
936
976
|
typeToString(c, errorTarget),
|
|
937
977
|
symbolToString(c, suggestion),
|
|
938
978
|
]);
|
|
939
979
|
else
|
|
940
|
-
this.reportError(
|
|
980
|
+
this.reportError(523 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
|
|
941
981
|
propName,
|
|
942
982
|
typeToString(c, errorTarget),
|
|
943
983
|
]);
|
|
@@ -959,16 +999,16 @@ export class Relater extends TypeComparer {
|
|
|
959
999
|
suggestion = getSpellingSuggestionForName(c, getText(name), getPropertiesOfType(c, errorTarget), 111551 /* SymbolFlags.Value */);
|
|
960
1000
|
}
|
|
961
1001
|
if (suggestion !== undefined)
|
|
962
|
-
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]);
|
|
963
1003
|
else
|
|
964
|
-
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)]);
|
|
965
1005
|
}
|
|
966
1006
|
return true;
|
|
967
1007
|
}
|
|
968
1008
|
if (checkTypes !== undefined &&
|
|
969
1009
|
this.isRelatedTo(getTypeOfSymbol(c, prop), getTypeOfPropertyInTypes(c, checkTypes, prop.name), 3 /* RecursionFlags.Both */, reportErrors) === 0 /* Ternary.False */) {
|
|
970
1010
|
if (reportErrors)
|
|
971
|
-
this.reportError(
|
|
1011
|
+
this.reportError(511 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, prop)]);
|
|
972
1012
|
return true;
|
|
973
1013
|
}
|
|
974
1014
|
}
|
|
@@ -1135,18 +1175,17 @@ export class Relater extends TypeComparer {
|
|
|
1135
1175
|
if (entry !== 0 /* RelationComparisonResult.None */) {
|
|
1136
1176
|
if (reportErrors &&
|
|
1137
1177
|
(entry & 2 /* RelationComparisonResult.Failed */) !== 0 &&
|
|
1138
|
-
(entry &
|
|
1178
|
+
(entry & 32 /* RelationComparisonResult.Overflow */) === 0) {
|
|
1139
1179
|
// Redo the failed comparison to elaborate.
|
|
1140
1180
|
}
|
|
1141
1181
|
else {
|
|
1142
1182
|
c.reliabilityFlags |=
|
|
1143
1183
|
entry & (8 /* RelationComparisonResult.ReportsUnmeasurable */ | 16 /* RelationComparisonResult.ReportsUnreliable */);
|
|
1144
|
-
if (reportErrors && (entry &
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
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
|
+
]);
|
|
1150
1189
|
return (entry & 1 /* RelationComparisonResult.Succeeded */) !== 0 ? -1 /* Ternary.True */ : 0 /* Ternary.False */;
|
|
1151
1190
|
}
|
|
1152
1191
|
}
|
|
@@ -1164,10 +1203,10 @@ export class Relater extends TypeComparer {
|
|
|
1164
1203
|
}
|
|
1165
1204
|
const sourceDepth = this.sourceDepth;
|
|
1166
1205
|
const targetDepth = this.targetDepth;
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
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 */;
|
|
1171
1210
|
const maybeStart = this.maybeKeys.length;
|
|
1172
1211
|
this.maybeKeys.push(id);
|
|
1173
1212
|
this.maybeKeysSet.add(id);
|
|
@@ -1204,17 +1243,21 @@ export class Relater extends TypeComparer {
|
|
|
1204
1243
|
}
|
|
1205
1244
|
else {
|
|
1206
1245
|
// False under assumptions is false without them.
|
|
1207
|
-
this.
|
|
1246
|
+
this.record(id, 2 /* RelationComparisonResult.Failed */ | propagatingVarianceFlags);
|
|
1208
1247
|
this.relationCount--;
|
|
1209
1248
|
this.resetMaybeStack(maybeStart, propagatingVarianceFlags, false);
|
|
1210
1249
|
}
|
|
1211
1250
|
return result;
|
|
1212
1251
|
}
|
|
1252
|
+
record(key, result) {
|
|
1253
|
+
if (this.relation.set(key, result) && this.addedKeys !== undefined)
|
|
1254
|
+
this.addedKeys.push(key);
|
|
1255
|
+
}
|
|
1213
1256
|
resetMaybeStack(maybeStart, propagatingVarianceFlags, markAllAsSucceeded) {
|
|
1214
1257
|
for (let i = maybeStart; i < this.maybeKeys.length; i++) {
|
|
1215
1258
|
this.maybeKeysSet.delete(this.maybeKeys[i]);
|
|
1216
1259
|
if (markAllAsSucceeded) {
|
|
1217
|
-
this.
|
|
1260
|
+
this.record(this.maybeKeys[i], 1 /* RelationComparisonResult.Succeeded */ | propagatingVarianceFlags);
|
|
1218
1261
|
this.relationCount--;
|
|
1219
1262
|
}
|
|
1220
1263
|
}
|
|
@@ -1907,7 +1950,7 @@ export class Relater extends TypeComparer {
|
|
|
1907
1950
|
? this.isRelatedTo(s, t, 3 /* RecursionFlags.Both */, false)
|
|
1908
1951
|
: compareTypesIdentical(c, s, t);
|
|
1909
1952
|
else {
|
|
1910
|
-
if (c.
|
|
1953
|
+
if (c.varianceStack.length !== 0 && (varianceFlags & 16 /* VarianceFlags.Unreliable */) !== 0)
|
|
1911
1954
|
instantiateType(c, s, c.reportUnreliableMapper);
|
|
1912
1955
|
if (variance === 1 /* VarianceFlags.Covariant */)
|
|
1913
1956
|
related = this.isRelatedToEx(s, t, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
@@ -1968,33 +2011,34 @@ export class Relater extends TypeComparer {
|
|
|
1968
2011
|
const sourceArity = getTypeReferenceArity(source);
|
|
1969
2012
|
const targetArity = getTypeReferenceArity(target);
|
|
1970
2013
|
const sourceRest = isTupleType(source) ? (tupleTargetOf(source).combinedFlags & 4 /* ElementFlags.Rest */) !== 0 : true;
|
|
1971
|
-
const targetHasRestElement = (targetTuple.combinedFlags &
|
|
2014
|
+
const targetHasRestElement = (targetTuple.combinedFlags & 4 /* ElementFlags.Rest */) !== 0;
|
|
2015
|
+
const targetHasVariableElement = (targetTuple.combinedFlags & 12 /* ElementFlags.Variable */) !== 0;
|
|
1972
2016
|
const sourceMinLength = isTupleType(source) ? tupleTargetOf(source).minLength : 0;
|
|
1973
2017
|
const targetMinLength = targetTuple.minLength;
|
|
1974
2018
|
if (!sourceRest && sourceArity < targetMinLength) {
|
|
1975
2019
|
if (reportErrors)
|
|
1976
|
-
this.reportError(
|
|
2020
|
+
this.reportError(769 /* Diagnostics.Source_has_0_element_s_but_target_requires_1 */, [
|
|
1977
2021
|
String(sourceArity),
|
|
1978
2022
|
String(targetMinLength),
|
|
1979
2023
|
]);
|
|
1980
2024
|
return 0 /* Ternary.False */;
|
|
1981
2025
|
}
|
|
1982
|
-
if (!
|
|
2026
|
+
if (!targetHasVariableElement && targetArity < sourceMinLength) {
|
|
1983
2027
|
if (reportErrors)
|
|
1984
|
-
this.reportError(
|
|
2028
|
+
this.reportError(770 /* Diagnostics.Source_has_0_element_s_but_target_allows_only_1 */, [
|
|
1985
2029
|
String(sourceMinLength),
|
|
1986
2030
|
String(targetArity),
|
|
1987
2031
|
]);
|
|
1988
2032
|
return 0 /* Ternary.False */;
|
|
1989
2033
|
}
|
|
1990
|
-
if (!
|
|
2034
|
+
if (!targetHasVariableElement && (sourceRest || targetArity < sourceArity)) {
|
|
1991
2035
|
if (reportErrors) {
|
|
1992
2036
|
if (sourceMinLength < targetMinLength)
|
|
1993
|
-
this.reportError(
|
|
2037
|
+
this.reportError(771 /* Diagnostics.Target_requires_0_element_s_but_source_may_have_fewer */, [
|
|
1994
2038
|
String(targetMinLength),
|
|
1995
2039
|
]);
|
|
1996
2040
|
else
|
|
1997
|
-
this.reportError(
|
|
2041
|
+
this.reportError(772 /* Diagnostics.Target_allows_only_0_element_s_but_source_may_have_more */, [
|
|
1998
2042
|
String(targetArity),
|
|
1999
2043
|
]);
|
|
2000
2044
|
}
|
|
@@ -2010,25 +2054,34 @@ export class Relater extends TypeComparer {
|
|
|
2010
2054
|
? tupleTargetOf(source).elementInfos[sourcePosition].flags
|
|
2011
2055
|
: 4 /* ElementFlags.Rest */;
|
|
2012
2056
|
const sourcePositionFromEnd = sourceArity - 1 - sourcePosition;
|
|
2013
|
-
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
|
|
2014
2067
|
? targetArity - 1 - Math.min(sourcePositionFromEnd, targetEndCount)
|
|
2015
2068
|
: sourcePosition;
|
|
2016
2069
|
const targetFlags = targetPosition >= 0 ? targetTuple.elementInfos[targetPosition].flags : 0 /* ElementFlags.None */;
|
|
2017
2070
|
if ((targetFlags & 8 /* ElementFlags.Variadic */) !== 0 && (sourceFlags & 8 /* ElementFlags.Variadic */) === 0) {
|
|
2018
2071
|
if (reportErrors)
|
|
2019
|
-
this.reportError(
|
|
2072
|
+
this.reportError(774 /* Diagnostics.Source_provides_no_match_for_variadic_element_at_position_0_in_target */, [
|
|
2020
2073
|
String(targetPosition),
|
|
2021
2074
|
]);
|
|
2022
2075
|
return 0 /* Ternary.False */;
|
|
2023
2076
|
}
|
|
2024
2077
|
if ((sourceFlags & 8 /* ElementFlags.Variadic */) !== 0 && (targetFlags & 12 /* ElementFlags.Variable */) === 0) {
|
|
2025
2078
|
if (reportErrors)
|
|
2026
|
-
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)]);
|
|
2027
2080
|
return 0 /* Ternary.False */;
|
|
2028
2081
|
}
|
|
2029
2082
|
if ((targetFlags & 1 /* ElementFlags.Required */) !== 0 && (sourceFlags & 1 /* ElementFlags.Required */) === 0) {
|
|
2030
2083
|
if (reportErrors)
|
|
2031
|
-
this.reportError(
|
|
2084
|
+
this.reportError(773 /* Diagnostics.Source_provides_no_match_for_required_element_at_position_0_in_target */, [
|
|
2032
2085
|
String(targetPosition),
|
|
2033
2086
|
]);
|
|
2034
2087
|
return 0 /* Ternary.False */;
|
|
@@ -2051,9 +2104,9 @@ export class Relater extends TypeComparer {
|
|
|
2051
2104
|
sourcePosition >= targetStartCount &&
|
|
2052
2105
|
sourcePositionFromEnd >= targetEndCount &&
|
|
2053
2106
|
targetStartCount !== sourceArity - targetEndCount - 1)
|
|
2054
|
-
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)]);
|
|
2055
2108
|
else
|
|
2056
|
-
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)]);
|
|
2057
2110
|
}
|
|
2058
2111
|
return 0 /* Ternary.False */;
|
|
2059
2112
|
}
|
|
@@ -2085,7 +2138,7 @@ export class Relater extends TypeComparer {
|
|
|
2085
2138
|
continue;
|
|
2086
2139
|
if (getPropertyOfObjectType(c, target, sourceProp.name) === undefined) {
|
|
2087
2140
|
if (reportErrors)
|
|
2088
|
-
this.reportError(
|
|
2141
|
+
this.reportError(523 /* Diagnostics.Property_0_does_not_exist_on_type_1 */, [
|
|
2089
2142
|
symbolToString(c, sourceProp),
|
|
2090
2143
|
typeToString(c, target),
|
|
2091
2144
|
]);
|
|
@@ -2124,12 +2177,12 @@ export class Relater extends TypeComparer {
|
|
|
2124
2177
|
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
|
|
2125
2178
|
if (reportErrors) {
|
|
2126
2179
|
if ((sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0 && (targetPropFlags & 2 /* ModifierFlags.Private */) !== 0)
|
|
2127
|
-
this.reportError(
|
|
2180
|
+
this.reportError(617 /* Diagnostics.Types_have_separate_declarations_of_a_private_property_0 */, [
|
|
2128
2181
|
symbolToString(c, targetProp),
|
|
2129
2182
|
]);
|
|
2130
2183
|
else {
|
|
2131
2184
|
const sourceIsPrivate = (sourcePropFlags & 2 /* ModifierFlags.Private */) !== 0;
|
|
2132
|
-
this.reportError(
|
|
2185
|
+
this.reportError(510 /* Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2 */, [
|
|
2133
2186
|
symbolToString(c, targetProp),
|
|
2134
2187
|
typeToString(c, sourceIsPrivate ? source : target),
|
|
2135
2188
|
typeToString(c, sourceIsPrivate ? target : source),
|
|
@@ -2142,7 +2195,7 @@ export class Relater extends TypeComparer {
|
|
|
2142
2195
|
else if ((targetPropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
|
|
2143
2196
|
if (!isValidOverrideOf(c, sourceProp, targetProp)) {
|
|
2144
2197
|
if (reportErrors)
|
|
2145
|
-
this.reportError(
|
|
2198
|
+
this.reportError(618 /* Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2 */, [
|
|
2146
2199
|
symbolToString(c, targetProp),
|
|
2147
2200
|
typeToString(c, getDeclaringClass(c, sourceProp) ?? source),
|
|
2148
2201
|
typeToString(c, getDeclaringClass(c, targetProp) ?? target),
|
|
@@ -2152,7 +2205,7 @@ export class Relater extends TypeComparer {
|
|
|
2152
2205
|
}
|
|
2153
2206
|
else if ((sourcePropFlags & 4 /* ModifierFlags.Protected */) !== 0) {
|
|
2154
2207
|
if (reportErrors)
|
|
2155
|
-
this.reportError(
|
|
2208
|
+
this.reportError(619 /* Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2 */, [
|
|
2156
2209
|
symbolToString(c, targetProp),
|
|
2157
2210
|
typeToString(c, source),
|
|
2158
2211
|
typeToString(c, target),
|
|
@@ -2167,7 +2220,7 @@ export class Relater extends TypeComparer {
|
|
|
2167
2220
|
const related = this.isPropertySymbolTypeRelated(sourceProp, targetProp, sourcePropType, reportErrors, intersectionState);
|
|
2168
2221
|
if (related === 0 /* Ternary.False */) {
|
|
2169
2222
|
if (reportErrors)
|
|
2170
|
-
this.reportError(
|
|
2223
|
+
this.reportError(511 /* Diagnostics.Types_of_property_0_are_incompatible */, [symbolToString(c, targetProp)]);
|
|
2171
2224
|
return 0 /* Ternary.False */;
|
|
2172
2225
|
}
|
|
2173
2226
|
if (!skipOptional &&
|
|
@@ -2175,7 +2228,7 @@ export class Relater extends TypeComparer {
|
|
|
2175
2228
|
(targetProp.flags & 106500 /* SymbolFlags.ClassMember */) !== 0 &&
|
|
2176
2229
|
(targetProp.flags & 16777216 /* SymbolFlags.Optional */) === 0) {
|
|
2177
2230
|
if (reportErrors)
|
|
2178
|
-
this.reportError(
|
|
2231
|
+
this.reportError(512 /* Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2 */, [
|
|
2179
2232
|
symbolToString(c, targetProp),
|
|
2180
2233
|
typeToString(c, source),
|
|
2181
2234
|
typeToString(c, target),
|
|
@@ -2204,7 +2257,7 @@ export class Relater extends TypeComparer {
|
|
|
2204
2257
|
(source.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
|
|
2205
2258
|
const description = getText(declarationName);
|
|
2206
2259
|
if (getPropertyOfType(c, source, getSymbolNameForPrivateIdentifier(source.symbol, description)) !== undefined) {
|
|
2207
|
-
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)]);
|
|
2208
2261
|
return;
|
|
2209
2262
|
}
|
|
2210
2263
|
}
|
|
@@ -2212,25 +2265,25 @@ export class Relater extends TypeComparer {
|
|
|
2212
2265
|
if (props.length === 1) {
|
|
2213
2266
|
const names = getTypeNamesForErrorDisplay(c, source, target);
|
|
2214
2267
|
const propName = symbolToString(c, unmatchedProperty);
|
|
2215
|
-
this.reportError(
|
|
2268
|
+
this.reportError(880 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */, [
|
|
2216
2269
|
propName,
|
|
2217
2270
|
names[0],
|
|
2218
2271
|
names[1],
|
|
2219
2272
|
]);
|
|
2220
2273
|
if (declarationCount(unmatchedProperty) !== 0)
|
|
2221
|
-
this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declaration,
|
|
2274
|
+
this.relatedInfo.push(createDiagnosticForNode(unmatchedProperty.declaration, 867 /* Diagnostics.X_0_is_declared_here */, [propName]));
|
|
2222
2275
|
}
|
|
2223
2276
|
else if (this.tryElaborateArrayLikeErrors(source, target, false)) {
|
|
2224
2277
|
const names = getTypeNamesForErrorDisplay(c, source, target);
|
|
2225
2278
|
if (props.length > 5)
|
|
2226
|
-
this.reportError(
|
|
2279
|
+
this.reportError(879 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more */, [
|
|
2227
2280
|
names[0],
|
|
2228
2281
|
names[1],
|
|
2229
2282
|
symbolNames(c, props.slice(0, 4)),
|
|
2230
2283
|
String(props.length - 4),
|
|
2231
2284
|
]);
|
|
2232
2285
|
else
|
|
2233
|
-
this.reportError(
|
|
2286
|
+
this.reportError(878 /* Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2 */, [
|
|
2234
2287
|
names[0],
|
|
2235
2288
|
names[1],
|
|
2236
2289
|
symbolNames(c, props),
|
|
@@ -2243,7 +2296,7 @@ export class Relater extends TypeComparer {
|
|
|
2243
2296
|
if (isTupleType(source)) {
|
|
2244
2297
|
if (tupleTargetOf(source).readonly && isMutableArrayOrTuple(c, target)) {
|
|
2245
2298
|
if (reportErrors)
|
|
2246
|
-
this.reportError(
|
|
2299
|
+
this.reportError(1097 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
|
|
2247
2300
|
typeToString(c, source),
|
|
2248
2301
|
typeToString(c, target),
|
|
2249
2302
|
]);
|
|
@@ -2253,7 +2306,7 @@ export class Relater extends TypeComparer {
|
|
|
2253
2306
|
}
|
|
2254
2307
|
if (isReadonlyArrayType(c, source) && isMutableArrayOrTuple(c, target)) {
|
|
2255
2308
|
if (reportErrors)
|
|
2256
|
-
this.reportError(
|
|
2309
|
+
this.reportError(1097 /* Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1 */, [
|
|
2257
2310
|
typeToString(c, source),
|
|
2258
2311
|
typeToString(c, target),
|
|
2259
2312
|
]);
|
|
@@ -2302,7 +2355,7 @@ export class Relater extends TypeComparer {
|
|
|
2302
2355
|
const targetIsAbstract = (targetSignatures[0].flags & 8 /* SignatureFlags.Abstract */) !== 0;
|
|
2303
2356
|
if (sourceIsAbstract && !targetIsAbstract) {
|
|
2304
2357
|
if (reportErrors)
|
|
2305
|
-
this.reportError(
|
|
2358
|
+
this.reportError(684 /* Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type */, []);
|
|
2306
2359
|
return 0 /* Ternary.False */;
|
|
2307
2360
|
}
|
|
2308
2361
|
if (!this.constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors))
|
|
@@ -2345,7 +2398,7 @@ export class Relater extends TypeComparer {
|
|
|
2345
2398
|
shouldElaborateErrors = false;
|
|
2346
2399
|
}
|
|
2347
2400
|
if (shouldElaborateErrors)
|
|
2348
|
-
this.reportError(
|
|
2401
|
+
this.reportError(799 /* Diagnostics.Type_0_provides_no_match_for_the_signature_1 */, [
|
|
2349
2402
|
typeToString(c, source),
|
|
2350
2403
|
signatureToString(c, t),
|
|
2351
2404
|
]);
|
|
@@ -2366,7 +2419,7 @@ export class Relater extends TypeComparer {
|
|
|
2366
2419
|
if (targetAccessibility !== 4 /* ModifierFlags.Protected */ && sourceAccessibility === 0)
|
|
2367
2420
|
return true;
|
|
2368
2421
|
if (reportErrors)
|
|
2369
|
-
this.reportError(
|
|
2422
|
+
this.reportError(813 /* Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type */, [
|
|
2370
2423
|
visibilityToString(sourceAccessibility),
|
|
2371
2424
|
visibilityToString(targetAccessibility),
|
|
2372
2425
|
]);
|
|
@@ -2439,7 +2492,7 @@ export class Relater extends TypeComparer {
|
|
|
2439
2492
|
isObjectTypeWithInferableIndex(c, source))
|
|
2440
2493
|
return this.membersRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
|
|
2441
2494
|
if (reportErrors)
|
|
2442
|
-
this.reportError(
|
|
2495
|
+
this.reportError(514 /* Diagnostics.Index_signature_for_type_0_is_missing_in_type_1 */, [
|
|
2443
2496
|
typeToString(c, targetInfo.keyType),
|
|
2444
2497
|
typeToString(c, source),
|
|
2445
2498
|
]);
|
|
@@ -2467,7 +2520,7 @@ export class Relater extends TypeComparer {
|
|
|
2467
2520
|
const related = this.isRelatedToEx(t, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
2468
2521
|
if (related === 0 /* Ternary.False */) {
|
|
2469
2522
|
if (reportErrors)
|
|
2470
|
-
this.reportError(
|
|
2523
|
+
this.reportError(695 /* Diagnostics.Property_0_is_incompatible_with_index_signature */, [symbolToString(c, prop)]);
|
|
2471
2524
|
return 0 /* Ternary.False */;
|
|
2472
2525
|
}
|
|
2473
2526
|
result &= related;
|
|
@@ -2487,9 +2540,9 @@ export class Relater extends TypeComparer {
|
|
|
2487
2540
|
const related = this.isRelatedToEx(sourceInfo.valueType, targetInfo.valueType, 3 /* RecursionFlags.Both */, reportErrors, undefined, intersectionState);
|
|
2488
2541
|
if (related === 0 /* Ternary.False */ && reportErrors) {
|
|
2489
2542
|
if (sourceInfo.keyType === targetInfo.keyType)
|
|
2490
|
-
this.reportError(
|
|
2543
|
+
this.reportError(784 /* Diagnostics.X_0_index_signatures_are_incompatible */, [typeToString(c, sourceInfo.keyType)]);
|
|
2491
2544
|
else
|
|
2492
|
-
this.reportError(
|
|
2545
|
+
this.reportError(515 /* Diagnostics.X_0_and_1_index_signatures_are_incompatible */, [
|
|
2493
2546
|
typeToString(c, sourceInfo.keyType),
|
|
2494
2547
|
typeToString(c, targetInfo.keyType),
|
|
2495
2548
|
]);
|
|
@@ -2523,7 +2576,7 @@ export class Relater extends TypeComparer {
|
|
|
2523
2576
|
if ((source.flags & 1048576 /* TypeFlags.Object */) !== 0 && (target.flags & 12713980 /* TypeFlags.Primitive */) !== 0)
|
|
2524
2577
|
this.tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
|
2525
2578
|
else if (source.symbol !== undefined && (source.flags & 1048576 /* TypeFlags.Object */) !== 0 && c.globalObjectType === source)
|
|
2526
|
-
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 */, []);
|
|
2527
2580
|
else if ((source.objectFlags & 2048 /* ObjectFlags.JsxAttributes */) !== 0 && (target.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
2528
2581
|
// Attributes failing JSX.IntrinsicAttributes or JSX.IntrinsicClassAttributes report that member's error alone.
|
|
2529
2582
|
const targetTypes = typesOf(target);
|
|
@@ -2538,7 +2591,7 @@ export class Relater extends TypeComparer {
|
|
|
2538
2591
|
else if ((originalTarget.flags & 268435456 /* TypeFlags.Intersection */) !== 0 &&
|
|
2539
2592
|
(lazyObjectFlags(c, originalTarget) & 67108864 /* ObjectFlags.IsNeverIntersection */) !== 0) {
|
|
2540
2593
|
const props = getPropertiesOfUnionOrIntersectionType(c, originalTarget);
|
|
2541
|
-
let message =
|
|
2594
|
+
let message = 1868 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents */;
|
|
2542
2595
|
let prop;
|
|
2543
2596
|
for (const p of props) {
|
|
2544
2597
|
if (isDiscriminantWithNeverType(c, p)) {
|
|
@@ -2548,7 +2601,7 @@ export class Relater extends TypeComparer {
|
|
|
2548
2601
|
}
|
|
2549
2602
|
if (prop === undefined) {
|
|
2550
2603
|
message =
|
|
2551
|
-
|
|
2604
|
+
1869 /* Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some */;
|
|
2552
2605
|
for (const p of props) {
|
|
2553
2606
|
if (isConflictingPrivateProperty(p)) {
|
|
2554
2607
|
prop = p;
|
|
@@ -2567,7 +2620,7 @@ export class Relater extends TypeComparer {
|
|
|
2567
2620
|
const syntheticParam = cloneTypeParameter(c, source);
|
|
2568
2621
|
syntheticParam.constraint = instantiateType(c, target, new SimpleTypeMapper(source, syntheticParam));
|
|
2569
2622
|
if (hasNonCircularBaseConstraint(c, syntheticParam)) {
|
|
2570
|
-
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)]));
|
|
2571
2624
|
}
|
|
2572
2625
|
}
|
|
2573
2626
|
}
|
|
@@ -2576,7 +2629,7 @@ export class Relater extends TypeComparer {
|
|
|
2576
2629
|
if ((source === c.globalStringType && target === c.stringType) ||
|
|
2577
2630
|
(source === c.globalNumberType && target === c.numberType) ||
|
|
2578
2631
|
(source === c.globalBooleanType && target === c.booleanType))
|
|
2579
|
-
this.reportError(
|
|
2632
|
+
this.reportError(831 /* Diagnostics.X_0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible */, [
|
|
2580
2633
|
typeToString(c, target),
|
|
2581
2634
|
typeToString(c, source),
|
|
2582
2635
|
]);
|
|
@@ -2602,14 +2655,20 @@ export class Relater extends TypeComparer {
|
|
|
2602
2655
|
target !== c.markerSuperTypeForCheck &&
|
|
2603
2656
|
target !== c.markerSubTypeForCheck) {
|
|
2604
2657
|
const constraint = getBaseConstraintOfType(c, target);
|
|
2605
|
-
if (
|
|
2606
|
-
|
|
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)]);
|
|
2607
2666
|
else if (constraint !== undefined && isTypeAssignableTo(c, source, constraint))
|
|
2608
|
-
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)]);
|
|
2609
2668
|
else {
|
|
2610
2669
|
// Reported once.
|
|
2611
2670
|
this.errorChain = undefined;
|
|
2612
|
-
this.reportError(
|
|
2671
|
+
this.reportError(1164 /* Diagnostics.X_0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1 */, [
|
|
2613
2672
|
targetType,
|
|
2614
2673
|
generalizedSourceType,
|
|
2615
2674
|
]);
|
|
@@ -2617,18 +2676,18 @@ export class Relater extends TypeComparer {
|
|
|
2617
2676
|
}
|
|
2618
2677
|
if (message === undefined) {
|
|
2619
2678
|
if (this.relation === c.comparableRelation)
|
|
2620
|
-
message =
|
|
2679
|
+
message = 819 /* Diagnostics.Type_0_is_not_comparable_to_type_1 */;
|
|
2621
2680
|
else if (sourceType === targetType)
|
|
2622
2681
|
message =
|
|
2623
|
-
|
|
2682
|
+
858 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated */;
|
|
2624
2683
|
else if (c.exactOptionalPropertyTypes && getExactOptionalUnassignableProperties(c, source, target).length !== 0)
|
|
2625
2684
|
message =
|
|
2626
|
-
|
|
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 */;
|
|
2627
2686
|
else {
|
|
2628
2687
|
if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 && (target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
|
|
2629
2688
|
const suggested = getSuggestedTypeForNonexistentStringLiteralType(c, source, target);
|
|
2630
2689
|
if (suggested !== undefined) {
|
|
2631
|
-
this.reportError(
|
|
2690
|
+
this.reportError(958 /* Diagnostics.Type_0_is_not_assignable_to_type_1_Did_you_mean_2 */, [
|
|
2632
2691
|
generalizedSourceType,
|
|
2633
2692
|
targetType,
|
|
2634
2693
|
typeToString(c, suggested),
|
|
@@ -2636,32 +2695,31 @@ export class Relater extends TypeComparer {
|
|
|
2636
2695
|
return;
|
|
2637
2696
|
}
|
|
2638
2697
|
}
|
|
2639
|
-
message =
|
|
2698
|
+
message = 507 /* Diagnostics.Type_0_is_not_assignable_to_type_1 */;
|
|
2640
2699
|
}
|
|
2641
2700
|
}
|
|
2642
|
-
else if (message ===
|
|
2701
|
+
else if (message === 528 /* Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 */ &&
|
|
2643
2702
|
c.exactOptionalPropertyTypes &&
|
|
2644
2703
|
getExactOptionalUnassignableProperties(c, source, target).length !== 0)
|
|
2645
2704
|
message =
|
|
2646
|
-
|
|
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 */;
|
|
2647
2706
|
switch (this.getChainMessage(0)) {
|
|
2648
2707
|
// Suppressed after an excess property error.
|
|
2649
|
-
case
|
|
2650
|
-
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 */:
|
|
2651
2710
|
return;
|
|
2652
|
-
case
|
|
2653
|
-
case
|
|
2654
|
-
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 */:
|
|
2655
2713
|
if (this.chainArgsMatch(generalizedSourceType, targetType, undefined))
|
|
2656
2714
|
return;
|
|
2657
2715
|
break;
|
|
2658
|
-
case
|
|
2716
|
+
case 880 /* Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2 */:
|
|
2659
2717
|
if (!isConversionOrInterfaceImplementationMessage(message) &&
|
|
2660
2718
|
this.chainArgsMatch(undefined, generalizedSourceType, targetType))
|
|
2661
2719
|
return;
|
|
2662
2720
|
break;
|
|
2663
|
-
case
|
|
2664
|
-
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 */:
|
|
2665
2723
|
if (!isConversionOrInterfaceImplementationMessage(message) &&
|
|
2666
2724
|
this.chainArgsMatch(generalizedSourceType, targetType, undefined))
|
|
2667
2725
|
return;
|
|
@@ -2670,44 +2728,44 @@ export class Relater extends TypeComparer {
|
|
|
2670
2728
|
this.reportError(message, [generalizedSourceType, targetType]);
|
|
2671
2729
|
}
|
|
2672
2730
|
reportError(message, args) {
|
|
2673
|
-
if (message ===
|
|
2731
|
+
if (message === 511 /* Diagnostics.Types_of_property_0_are_incompatible */) {
|
|
2674
2732
|
switch (this.getChainMessage(0)) {
|
|
2675
|
-
case
|
|
2676
|
-
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 */:
|
|
2677
2735
|
return;
|
|
2678
2736
|
}
|
|
2679
2737
|
// A property followed by a return type incompatibility becomes one message for `x()`.
|
|
2680
2738
|
let arg = '';
|
|
2681
2739
|
switch (this.getChainMessage(1)) {
|
|
2682
|
-
case
|
|
2740
|
+
case 476 /* Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
|
|
2683
2741
|
arg = getPropertyNameArg(args[0]) + '()';
|
|
2684
2742
|
break;
|
|
2685
|
-
case
|
|
2743
|
+
case 477 /* Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1 */:
|
|
2686
2744
|
arg = 'new ' + getPropertyNameArg(args[0]) + '()';
|
|
2687
2745
|
break;
|
|
2688
|
-
case
|
|
2746
|
+
case 474 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */:
|
|
2689
2747
|
arg = getPropertyNameArg(args[0]) + '(...)';
|
|
2690
2748
|
break;
|
|
2691
|
-
case
|
|
2749
|
+
case 475 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */:
|
|
2692
2750
|
arg = 'new ' + getPropertyNameArg(args[0]) + '(...)';
|
|
2693
2751
|
break;
|
|
2694
2752
|
}
|
|
2695
2753
|
if (arg !== '') {
|
|
2696
|
-
message =
|
|
2754
|
+
message = 473 /* Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types */;
|
|
2697
2755
|
args = [arg];
|
|
2698
2756
|
this.errorChain = this.errorChain.next.next;
|
|
2699
2757
|
}
|
|
2700
2758
|
// Nested property incompatibilities become one message for `x.y`.
|
|
2701
2759
|
switch (this.getChainMessage(1)) {
|
|
2702
|
-
case
|
|
2703
|
-
case
|
|
2704
|
-
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 */: {
|
|
2705
2763
|
const head = getPropertyNameArg(args[0]);
|
|
2706
2764
|
const tail = getPropertyNameArg(this.errorChain.next.args[0]);
|
|
2707
2765
|
const dotted = addToDottedName(head, tail);
|
|
2708
2766
|
this.errorChain = this.errorChain.next.next;
|
|
2709
|
-
if (message ===
|
|
2710
|
-
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 */;
|
|
2711
2769
|
this.reportError(message, [dotted]);
|
|
2712
2770
|
return;
|
|
2713
2771
|
}
|
|
@@ -2785,7 +2843,7 @@ export function getSingleBaseForNonAugmentingSubtype(c, t) {
|
|
|
2785
2843
|
const baseTypeNode = declaration !== undefined ? getExtendsHeritageClauseElement(declaration) : undefined;
|
|
2786
2844
|
if (baseTypeNode !== undefined) {
|
|
2787
2845
|
const expression = getExpression(baseTypeNode);
|
|
2788
|
-
if (expression.kind !== 79 /* SyntaxKind.Identifier */ && expression.kind !==
|
|
2846
|
+
if (expression.kind !== 79 /* SyntaxKind.Identifier */ && expression.kind !== 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
2789
2847
|
return undefined;
|
|
2790
2848
|
}
|
|
2791
2849
|
}
|
|
@@ -2922,12 +2980,12 @@ function isIgnoredJsxProperty(source, prop) {
|
|
|
2922
2980
|
}
|
|
2923
2981
|
function isObjectLiteralElement(node) {
|
|
2924
2982
|
switch (node.kind) {
|
|
2925
|
-
case
|
|
2926
|
-
case
|
|
2927
|
-
case
|
|
2928
|
-
case
|
|
2929
|
-
case
|
|
2930
|
-
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 */:
|
|
2931
2989
|
return true;
|
|
2932
2990
|
}
|
|
2933
2991
|
return false;
|
|
@@ -3055,13 +3113,13 @@ export function isDiscriminantProperty(c, t, name) {
|
|
|
3055
3113
|
const prop = getUnionOrIntersectionProperty(c, t, name, false);
|
|
3056
3114
|
if (prop === undefined || (prop.checkFlags & 2 /* CheckFlags.SyntheticProperty */) === 0)
|
|
3057
3115
|
return false;
|
|
3058
|
-
if ((prop.checkFlags &
|
|
3059
|
-
prop.checkFlags |=
|
|
3116
|
+
if ((prop.checkFlags & 16777216 /* CheckFlags.IsDiscriminantComputed */) === 0) {
|
|
3117
|
+
prop.checkFlags |= 16777216 /* CheckFlags.IsDiscriminantComputed */;
|
|
3060
3118
|
if ((prop.checkFlags & 192 /* CheckFlags.NonUniformAndLiteral */) === 192 /* CheckFlags.NonUniformAndLiteral */ &&
|
|
3061
3119
|
!isGenericTypeLocal(c, getTypeOfSymbol(c, prop)))
|
|
3062
|
-
prop.checkFlags |=
|
|
3120
|
+
prop.checkFlags |= 33554432 /* CheckFlags.IsDiscriminant */;
|
|
3063
3121
|
}
|
|
3064
|
-
return (prop.checkFlags &
|
|
3122
|
+
return (prop.checkFlags & 33554432 /* CheckFlags.IsDiscriminant */) !== 0;
|
|
3065
3123
|
}
|
|
3066
3124
|
import { isGenericType as isGenericTypeLocal } from './checker-type-operators.js';
|
|
3067
3125
|
/** The constituent selected by a key property's unit type; not computed yet. */
|
|
@@ -3279,14 +3337,14 @@ function contextFreeExpressionDeclaration(c, t) {
|
|
|
3279
3337
|
if (declaration === undefined)
|
|
3280
3338
|
return undefined;
|
|
3281
3339
|
switch (declaration.kind) {
|
|
3282
|
-
case
|
|
3283
|
-
case
|
|
3284
|
-
case
|
|
3285
|
-
case
|
|
3286
|
-
case
|
|
3287
|
-
case
|
|
3288
|
-
case
|
|
3289
|
-
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 */:
|
|
3290
3348
|
return isContextSensitive(c, declaration) ? undefined : declaration;
|
|
3291
3349
|
}
|
|
3292
3350
|
return undefined;
|
|
@@ -3324,14 +3382,14 @@ export function setStackEntry(stack, depth, t) {
|
|
|
3324
3382
|
export function isDeeplyNestedType(c, t, stack, depth, maxDepth) {
|
|
3325
3383
|
if (depth < maxDepth)
|
|
3326
3384
|
return false;
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
|
|
3331
|
-
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))
|
|
3332
3388
|
if (isDeeplyNestedType(c, u, stack, depth, maxDepth))
|
|
3333
3389
|
return true;
|
|
3334
|
-
|
|
3390
|
+
return false;
|
|
3391
|
+
}
|
|
3392
|
+
const identity = getRecursionIdentityFromTarget(target);
|
|
3335
3393
|
let count = 0;
|
|
3336
3394
|
let lastTypeId = 0;
|
|
3337
3395
|
for (let i = 0; i < depth; i++) {
|
|
@@ -3347,8 +3405,64 @@ export function isDeeplyNestedType(c, t, stack, depth, maxDepth) {
|
|
|
3347
3405
|
}
|
|
3348
3406
|
return false;
|
|
3349
3407
|
}
|
|
3350
|
-
|
|
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) {
|
|
3351
3461
|
for (;;) {
|
|
3462
|
+
if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
|
|
3463
|
+
t = t.objectType;
|
|
3464
|
+
continue;
|
|
3465
|
+
}
|
|
3352
3466
|
if ((t.objectFlags & 96 /* ObjectFlags.InstantiatedMapped */) === 96 /* ObjectFlags.InstantiatedMapped */ &&
|
|
3353
3467
|
(t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
3354
3468
|
const target = getModifiersTypeFromMappedType(c, t);
|
|
@@ -3362,38 +3476,33 @@ function getMappedTargetWithSymbol(c, t) {
|
|
|
3362
3476
|
}
|
|
3363
3477
|
}
|
|
3364
3478
|
function hasMatchingRecursionIdentity(c, t, identity) {
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
3369
|
-
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))
|
|
3370
3482
|
if (hasMatchingRecursionIdentity(c, u, identity))
|
|
3371
3483
|
return true;
|
|
3372
3484
|
return false;
|
|
3373
3485
|
}
|
|
3374
|
-
return
|
|
3486
|
+
return getRecursionIdentityFromTarget(target) === identity;
|
|
3375
3487
|
}
|
|
3376
3488
|
/** An identity shared by instantiations of a type, so infinitely expanding instantiations can be detected. */
|
|
3377
|
-
export function getRecursionIdentity(t) {
|
|
3489
|
+
export function getRecursionIdentity(c, t) {
|
|
3490
|
+
return getRecursionIdentityFromTarget(getRecursionIdentityTarget(c, t));
|
|
3491
|
+
}
|
|
3492
|
+
function getRecursionIdentityFromTarget(t) {
|
|
3378
3493
|
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
|
|
3379
3494
|
(t.objectFlags & (128 /* ObjectFlags.ObjectLiteral */ | 16384 /* ObjectFlags.ArrayLiteral */)) === 0) {
|
|
3380
3495
|
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && t.node !== undefined)
|
|
3381
3496
|
return nodeRecursionId(t.node);
|
|
3382
3497
|
if (t.symbol !== undefined &&
|
|
3383
3498
|
!((t.objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0 && (t.symbol.flags & 32 /* SymbolFlags.Class */) !== 0) &&
|
|
3384
|
-
(t.objectFlags &
|
|
3499
|
+
(t.objectFlags & 536870912 /* ObjectFlags.FromTypeNode */) === 0)
|
|
3385
3500
|
return symbolRecursionId(t.symbol);
|
|
3386
|
-
if (isTupleType(t) && (t.objectFlags &
|
|
3501
|
+
if (isTupleType(t) && (t.objectFlags & 536870912 /* ObjectFlags.FromTypeNode */) === 0)
|
|
3387
3502
|
return typeRecursionId(t.target);
|
|
3388
3503
|
}
|
|
3389
3504
|
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && t.symbol !== undefined)
|
|
3390
3505
|
return symbolRecursionId(t.symbol);
|
|
3391
|
-
if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
|
|
3392
|
-
let objectType = t.objectType;
|
|
3393
|
-
while ((objectType.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0)
|
|
3394
|
-
objectType = objectType.objectType;
|
|
3395
|
-
return typeRecursionId(objectType);
|
|
3396
|
-
}
|
|
3397
3506
|
if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
|
|
3398
3507
|
return nodeRecursionId(t.root.node);
|
|
3399
3508
|
return typeRecursionId(t);
|
|
@@ -3424,17 +3533,50 @@ export function getAliasVariances(c, symbol) {
|
|
|
3424
3533
|
* The measured variance of each type parameter, from relating marker instantiations; empty when
|
|
3425
3534
|
* requested recursively.
|
|
3426
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
|
+
}
|
|
3427
3545
|
function getVariancesWorker(c, symbol, typeParameters) {
|
|
3428
3546
|
const links = c.symbolLinks(symbol);
|
|
3429
3547
|
if (links.variances !== undefined)
|
|
3430
3548
|
return links.variances;
|
|
3431
|
-
|
|
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
|
+
}
|
|
3432
3576
|
const saveResolutionStart = c.resolutionStart;
|
|
3433
|
-
if (
|
|
3434
|
-
c.inVarianceComputation = true;
|
|
3577
|
+
if (c.varianceStack.length === 0)
|
|
3435
3578
|
c.resolutionStart = c.resolutionDepth;
|
|
3436
|
-
|
|
3437
|
-
links.variances = [];
|
|
3579
|
+
c.varianceStack.push(new VarianceStackEntry(symbol, typeParameters));
|
|
3438
3580
|
const variances = [];
|
|
3439
3581
|
for (const tp of typeParameters) {
|
|
3440
3582
|
const modifiers = getTypeParameterModifiers(tp);
|
|
@@ -3461,14 +3603,24 @@ function getVariancesWorker(c, symbol, typeParameters) {
|
|
|
3461
3603
|
variance |= 16 /* VarianceFlags.Unreliable */;
|
|
3462
3604
|
c.reliabilityFlags = saveReliabilityFlags;
|
|
3463
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;
|
|
3464
3610
|
variances.push(variance);
|
|
3465
3611
|
}
|
|
3466
|
-
|
|
3467
|
-
|
|
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)
|
|
3468
3618
|
c.resolutionStart = saveResolutionStart;
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
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;
|
|
3472
3624
|
}
|
|
3473
3625
|
export function createMarkerType(c, symbol, source, target) {
|
|
3474
3626
|
const mapper = new SimpleTypeMapper(source, target);
|
|
@@ -3668,7 +3820,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3668
3820
|
: getMinArgumentCount(c, source) > targetCount);
|
|
3669
3821
|
if (sourceHasMoreParameters) {
|
|
3670
3822
|
if (reportErrors && (checkMode & 8 /* SignatureCheckMode.StrictArity */) === 0)
|
|
3671
|
-
comparer.report(
|
|
3823
|
+
comparer.report(976 /* Diagnostics.Target_signature_provides_too_few_arguments_Expected_0_or_more_but_got_1 */, [
|
|
3672
3824
|
String(getMinArgumentCount(c, source)),
|
|
3673
3825
|
String(targetCount),
|
|
3674
3826
|
]);
|
|
@@ -3686,9 +3838,9 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3686
3838
|
const kind = target.declaration !== undefined ? target.declaration.kind : 0 /* SyntaxKind.Unknown */;
|
|
3687
3839
|
const strictVariance = (checkMode & 3 /* SignatureCheckMode.Callback */) === 0 &&
|
|
3688
3840
|
c.strictFunctionTypes &&
|
|
3689
|
-
kind !==
|
|
3690
|
-
kind !==
|
|
3691
|
-
kind !==
|
|
3841
|
+
kind !== 176 /* SyntaxKind.MethodDeclaration */ &&
|
|
3842
|
+
kind !== 175 /* SyntaxKind.MethodSignature */ &&
|
|
3843
|
+
kind !== 178 /* SyntaxKind.Constructor */;
|
|
3692
3844
|
let result = -1 /* Ternary.True */;
|
|
3693
3845
|
const sourceThisType = getThisTypeOfSignature(c, source);
|
|
3694
3846
|
if (sourceThisType !== undefined && sourceThisType !== c.voidType) {
|
|
@@ -3700,7 +3852,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3700
3852
|
related = comparer.compare(targetThisType, sourceThisType, reportErrors);
|
|
3701
3853
|
if (related === 0 /* Ternary.False */) {
|
|
3702
3854
|
if (reportErrors)
|
|
3703
|
-
comparer.report(
|
|
3855
|
+
comparer.report(825 /* Diagnostics.The_this_types_of_each_signature_are_incompatible */, []);
|
|
3704
3856
|
return 0 /* Ternary.False */;
|
|
3705
3857
|
}
|
|
3706
3858
|
result &= related;
|
|
@@ -3750,7 +3902,7 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3750
3902
|
related = 0 /* Ternary.False */;
|
|
3751
3903
|
if (related === 0 /* Ternary.False */) {
|
|
3752
3904
|
if (reportErrors)
|
|
3753
|
-
comparer.report(
|
|
3905
|
+
comparer.report(513 /* Diagnostics.Types_of_parameters_0_and_1_are_incompatible */, [
|
|
3754
3906
|
getParameterNameAtPosition(c, source, i),
|
|
3755
3907
|
getParameterNameAtPosition(c, target, i),
|
|
3756
3908
|
]);
|
|
@@ -3789,11 +3941,11 @@ export function compareSignaturesRelated(c, source, target, checkMode, reportErr
|
|
|
3789
3941
|
const construct = (source.flags & 4 /* SignatureFlags.Construct */) !== 0;
|
|
3790
3942
|
const message = source.parameters.length === 0 && target.parameters.length === 0
|
|
3791
3943
|
? construct
|
|
3792
|
-
?
|
|
3793
|
-
:
|
|
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 */
|
|
3794
3946
|
: construct
|
|
3795
|
-
?
|
|
3796
|
-
:
|
|
3947
|
+
? 475 /* Diagnostics.Construct_signature_return_types_0_and_1_are_incompatible */
|
|
3948
|
+
: 474 /* Diagnostics.Call_signature_return_types_0_and_1_are_incompatible */;
|
|
3797
3949
|
comparer.report(message, [typeToString(c, sourceReturnType), typeToString(c, targetReturnType)]);
|
|
3798
3950
|
}
|
|
3799
3951
|
}
|
|
@@ -3809,7 +3961,7 @@ function isInstantiatedGenericParameter(c, signature, pos) {
|
|
|
3809
3961
|
function compareTypePredicateRelatedTo(c, source, target, reportErrors, comparer) {
|
|
3810
3962
|
if (source.kind !== target.kind) {
|
|
3811
3963
|
if (reportErrors) {
|
|
3812
|
-
comparer.report(
|
|
3964
|
+
comparer.report(685 /* Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard */, []);
|
|
3813
3965
|
comparer.report(176 /* Diagnostics.Type_predicate_0_is_not_assignable_to_1 */, [
|
|
3814
3966
|
typePredicateToString(c, source),
|
|
3815
3967
|
typePredicateToString(c, target),
|
|
@@ -3986,6 +4138,7 @@ export function isExactOptionalPropertyMismatch(c, source, target) {
|
|
|
3986
4138
|
containsMissingType(c, target));
|
|
3987
4139
|
}
|
|
3988
4140
|
/** The string literal member of `target` closest to the string literal `source`. */
|
|
4141
|
+
const maxStringLiteralSuggestionCandidates = 1000;
|
|
3989
4142
|
function getSuggestedTypeForNonexistentStringLiteralType(c, source, target) {
|
|
3990
4143
|
const value = source.stringValue;
|
|
3991
4144
|
const valueCodePoints = new CodePoints();
|
|
@@ -3994,9 +4147,13 @@ function getSuggestedTypeForNonexistentStringLiteralType(c, source, target) {
|
|
|
3994
4147
|
let bestDistance = Math.floor(valueCodePoints.length * 0.4) + 0.9;
|
|
3995
4148
|
let best = undefined;
|
|
3996
4149
|
const lowerValue = value.toLowerCase();
|
|
4150
|
+
// A target with more string literal candidates than this gets no suggestion.
|
|
4151
|
+
let candidates = 0;
|
|
3997
4152
|
for (const t of typesOf(target)) {
|
|
3998
4153
|
if ((t.flags & 1024 /* TypeFlags.StringLiteral */) === 0)
|
|
3999
4154
|
continue;
|
|
4155
|
+
if (++candidates > maxStringLiteralSuggestionCandidates)
|
|
4156
|
+
return undefined;
|
|
4000
4157
|
const name = t.stringValue;
|
|
4001
4158
|
const nameLength = utf8Length(name);
|
|
4002
4159
|
if (name === '' || Math.abs(nameLength - valueCodePoints.length) > maximumLengthDifference || name === value)
|