@@ -171,6 +171,7 @@ import {
171
171
EnumMember,
172
172
EnumType,
173
173
equateValues,
174
+ ErrorOutputContainer,
174
175
escapeLeadingUnderscores,
175
176
escapeString,
176
177
EvaluatorResult,
@@ -20608,7 +20609,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20608
20609
expr: Expression | undefined,
20609
20610
headMessage: DiagnosticMessage | undefined,
20610
20611
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20611
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20612
+ errorOutputContainer: ErrorOutputContainer | undefined,
20612
20613
): boolean {
20613
20614
if (isTypeRelatedTo(source, target, relation)) return true;
20614
20615
if (!errorNode || !elaborateError(expr, source, target, relation, headMessage, containingMessageChain, errorOutputContainer)) {
@@ -20628,7 +20629,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20628
20629
relation: Map<string, RelationComparisonResult>,
20629
20630
headMessage: DiagnosticMessage | undefined,
20630
20631
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20631
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20632
+ errorOutputContainer: ErrorOutputContainer | undefined,
20632
20633
): boolean {
20633
20634
if (!node || isOrHasGenericConditional(target)) return false;
20634
20635
if (
@@ -20672,7 +20673,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20672
20673
relation: Map<string, RelationComparisonResult>,
20673
20674
headMessage: DiagnosticMessage | undefined,
20674
20675
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20675
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20676
+ errorOutputContainer: ErrorOutputContainer | undefined,
20676
20677
): boolean {
20677
20678
const callSignatures = getSignaturesOfType(source, SignatureKind.Call);
20678
20679
const constructSignatures = getSignaturesOfType(source, SignatureKind.Construct);
@@ -20705,7 +20706,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20705
20706
target: Type,
20706
20707
relation: Map<string, RelationComparisonResult>,
20707
20708
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20708
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20709
+ errorOutputContainer: ErrorOutputContainer | undefined,
20709
20710
): boolean {
20710
20711
// Don't elaborate blocks
20711
20712
if (isBlock(node.body)) {
@@ -20796,7 +20797,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20796
20797
target: Type,
20797
20798
relation: Map<string, RelationComparisonResult>,
20798
20799
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20799
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20800
+ errorOutputContainer: ErrorOutputContainer | undefined,
20800
20801
) {
20801
20802
// Assignability failure - check each prop individually, and if that fails, fall back on the bad error span
20802
20803
let reportedError = false;
@@ -20876,7 +20877,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20876
20877
target: Type,
20877
20878
relation: Map<string, RelationComparisonResult>,
20878
20879
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20879
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20880
+ errorOutputContainer: ErrorOutputContainer | undefined,
20880
20881
) {
20881
20882
const tupleOrArrayLikeTargetParts = filterType(target, isArrayOrTupleLikeType);
20882
20883
const nonTupleOrArrayLikeTargetParts = filterType(target, t => !isArrayOrTupleLikeType(t));
@@ -20978,7 +20979,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20978
20979
target: Type,
20979
20980
relation: Map<string, RelationComparisonResult>,
20980
20981
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
20981
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
20982
+ errorOutputContainer: ErrorOutputContainer | undefined,
20982
20983
) {
20983
20984
let result = elaborateElementwise(generateJsxAttributes(node), source, target, relation, containingMessageChain, errorOutputContainer);
20984
20985
let invalidTextDiagnostic: DiagnosticMessage | undefined;
@@ -21092,7 +21093,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21092
21093
target: Type,
21093
21094
relation: Map<string, RelationComparisonResult>,
21094
21095
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
21095
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
21096
+ errorOutputContainer: ErrorOutputContainer | undefined,
21096
21097
) {
21097
21098
if (target.flags & (TypeFlags.Primitive | TypeFlags.Never)) return false;
21098
21099
if (isTupleLikeType(source)) {
@@ -21139,7 +21140,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21139
21140
target: Type,
21140
21141
relation: Map<string, RelationComparisonResult>,
21141
21142
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
21142
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } | undefined,
21143
+ errorOutputContainer: ErrorOutputContainer | undefined,
21143
21144
) {
21144
21145
if (target.flags & (TypeFlags.Primitive | TypeFlags.Never)) return false;
21145
21146
return elaborateElementwise(generateObjectLiteralElements(node), source, target, relation, containingMessageChain, errorOutputContainer);
@@ -21637,7 +21638,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21637
21638
errorNode: Node | undefined,
21638
21639
headMessage?: DiagnosticMessage,
21639
21640
containingMessageChain?: () => DiagnosticMessageChain | undefined,
21640
- errorOutputContainer?: { errors?: Diagnostic[]; skipLogging?: boolean; } ,
21641
+ errorOutputContainer?: ErrorOutputContainer ,
21641
21642
): boolean {
21642
21643
let errorInfo: DiagnosticMessageChain | undefined;
21643
21644
let relatedInfo: [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] | undefined;
@@ -35186,7 +35187,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
35186
35187
checkMode: CheckMode,
35187
35188
reportErrors: boolean,
35188
35189
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
35189
- errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } ,
35190
+ errorOutputContainer: ErrorOutputContainer ,
35190
35191
) {
35191
35192
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
35192
35193
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
@@ -35302,7 +35303,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
35302
35303
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
35303
35304
inferenceContext: InferenceContext | undefined,
35304
35305
): readonly Diagnostic[] | undefined {
35305
- const errorOutputContainer: { errors?: Diagnostic[]; skipLogging?: boolean; } = { errors: undefined, skipLogging: true };
35306
+ const errorOutputContainer: ErrorOutputContainer = { errors: undefined, skipLogging: true };
35306
35307
if (isJsxCallLike(node)) {
35307
35308
if (!checkApplicableSignatureForJsxCallLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
35308
35309
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "jsx should have errors when reporting errors");
@@ -44934,7 +44935,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
44934
44935
}
44935
44936
44936
44937
if (!(type.flags & TypeFlags.Union)) {
44937
- const errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined = errorNode ? { errors: undefined } : undefined;
44938
+ const errorOutputContainer: ErrorOutputContainer | undefined = errorNode ? { errors: undefined, skipLogging: true } : undefined;
44938
44939
const iterationTypes = getIterationTypesOfIterableWorker(type, use, errorNode, errorOutputContainer);
44939
44940
if (iterationTypes === noIterationTypes) {
44940
44941
if (errorNode) {
@@ -44959,7 +44960,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
44959
44960
44960
44961
let allIterationTypes: IterationTypes[] | undefined;
44961
44962
for (const constituent of (type as UnionType).types) {
44962
- const errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined = errorNode ? { errors: undefined } : undefined;
44963
+ const errorOutputContainer: ErrorOutputContainer | undefined = errorNode ? { errors: undefined } : undefined;
44963
44964
const iterationTypes = getIterationTypesOfIterableWorker(constituent, use, errorNode, errorOutputContainer);
44964
44965
if (iterationTypes === noIterationTypes) {
44965
44966
if (errorNode) {
@@ -45010,7 +45011,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45010
45011
* NOTE: You probably don't want to call this directly and should be calling
45011
45012
* `getIterationTypesOfIterable` instead.
45012
45013
*/
45013
- function getIterationTypesOfIterableWorker(type: Type, use: IterationUse, errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined) {
45014
+ function getIterationTypesOfIterableWorker(type: Type, use: IterationUse, errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined) {
45014
45015
if (isTypeAny(type)) {
45015
45016
return anyIterationTypes;
45016
45017
}
@@ -45152,19 +45153,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45152
45153
* NOTE: You probably don't want to call this directly and should be calling
45153
45154
* `getIterationTypesOfIterable` instead.
45154
45155
*/
45155
- function getIterationTypesOfIterableSlow(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined, noCache: boolean) {
45156
+ function getIterationTypesOfIterableSlow(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined, noCache: boolean) {
45156
45157
const method = getPropertyOfType(type, getPropertyNameForKnownSymbolName(resolver.iteratorSymbolName));
45157
45158
const methodType = method && !(method.flags & SymbolFlags.Optional) ? getTypeOfSymbol(method) : undefined;
45158
45159
if (isTypeAny(methodType)) {
45159
45160
return noCache ? anyIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, anyIterationTypes);
45160
45161
}
45161
45162
45162
- const signatures = methodType ? getSignaturesOfType(methodType, SignatureKind.Call) : undefined;
45163
- if (!some(signatures)) {
45163
+ const allSignatures = methodType ? getSignaturesOfType(methodType, SignatureKind.Call) : undefined;
45164
+ const validSignatures = filter(allSignatures, sig => getMinArgumentCount(sig) === 0);
45165
+ if (!some(validSignatures)) {
45166
+ if (errorNode && some(allSignatures)) {
45167
+ checkTypeAssignableTo(type, resolver.getGlobalIterableType(/*reportErrors*/ true), errorNode, /*headMessage*/ undefined, /*containingMessageChain*/ undefined, errorOutputContainer);
45168
+ }
45164
45169
return noCache ? noIterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, noIterationTypes);
45165
45170
}
45166
45171
45167
- const iteratorType = getIntersectionType(map(signatures , getReturnTypeOfSignature));
45172
+ const iteratorType = getIntersectionType(map(validSignatures , getReturnTypeOfSignature));
45168
45173
const iterationTypes = getIterationTypesOfIteratorWorker(iteratorType, resolver, errorNode, errorOutputContainer, noCache) ?? noIterationTypes;
45169
45174
return noCache ? iterationTypes : setCachedIterationTypes(type, resolver.iterableCacheKey, iterationTypes);
45170
45175
}
@@ -45193,7 +45198,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45193
45198
* If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
45194
45199
* record is returned. Otherwise, `undefined` is returned.
45195
45200
*/
45196
- function getIterationTypesOfIterator(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined) {
45201
+ function getIterationTypesOfIterator(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined) {
45197
45202
return getIterationTypesOfIteratorWorker(type, resolver, errorNode, errorOutputContainer, /*noCache*/ false);
45198
45203
}
45199
45204
@@ -45206,7 +45211,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45206
45211
* NOTE: You probably don't want to call this directly and should be calling
45207
45212
* `getIterationTypesOfIterator` instead.
45208
45213
*/
45209
- function getIterationTypesOfIteratorWorker(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined, noCache: boolean) {
45214
+ function getIterationTypesOfIteratorWorker(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined, noCache: boolean) {
45210
45215
if (isTypeAny(type)) {
45211
45216
return anyIterationTypes;
45212
45217
}
@@ -45348,7 +45353,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45348
45353
* If we successfully found the *yield*, *return*, and *next* types, an `IterationTypes`
45349
45354
* record is returned. Otherwise, we return `undefined`.
45350
45355
*/
45351
- function getIterationTypesOfMethod(type: Type, resolver: IterationTypesResolver, methodName: "next" | "return" | "throw", errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined): IterationTypes | undefined {
45356
+ function getIterationTypesOfMethod(type: Type, resolver: IterationTypesResolver, methodName: "next" | "return" | "throw", errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined): IterationTypes | undefined {
45352
45357
const method = getPropertyOfType(type, methodName as __String);
45353
45358
45354
45359
// Ignore 'return' or 'throw' if they are missing.
@@ -45468,7 +45473,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45468
45473
* NOTE: You probably don't want to call this directly and should be calling
45469
45474
* `getIterationTypesOfIterator` instead.
45470
45475
*/
45471
- function getIterationTypesOfIteratorSlow(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: { errors: Diagnostic[] | undefined; } | undefined, noCache: boolean) {
45476
+ function getIterationTypesOfIteratorSlow(type: Type, resolver: IterationTypesResolver, errorNode: Node | undefined, errorOutputContainer: ErrorOutputContainer | undefined, noCache: boolean) {
45472
45477
const iterationTypes = combineIterationTypes([
45473
45478
getIterationTypesOfMethod(type, resolver, "next", errorNode, errorOutputContainer),
45474
45479
getIterationTypesOfMethod(type, resolver, "return", errorNode, errorOutputContainer),
0 commit comments