Skip to content

Commit 20c0e8b

Browse files
Update LKG.
1 parent 68465f8 commit 20c0e8b

10 files changed

+249
-222
lines changed

lib/lib.es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ declare var Function: FunctionConstructor;
318318
/**
319319
* Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
320320
*/
321-
type ThisParameterType<T> = T extends (this: unknown, ...args: any[]) => any ? unknown : T extends (this: infer U, ...args: any[]) => any ? U : unknown;
321+
type ThisParameterType<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown;
322322

323323
/**
324324
* Removes the 'this' parameter from a function type.

lib/tsc.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,7 +4351,7 @@ var ts;
43514351
Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types: diag(1368, ts.DiagnosticCategory.Message, "Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types_1368", "Specify emit/checking behavior for imports that are only used for types"),
43524352
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
43534353
Only_ECMAScript_imports_may_use_import_type: diag(1370, ts.DiagnosticCategory.Error, "Only_ECMAScript_imports_may_use_import_type_1370", "Only ECMAScript imports may use 'import type'."),
4354-
This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error: diag(1371, ts.DiagnosticCategory.Error, "This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_s_1371", "This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValue' is set to 'error'."),
4354+
This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error: diag(1371, ts.DiagnosticCategory.Error, "This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is__1371", "This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'."),
43554355
This_import_may_be_converted_to_a_type_only_import: diag(1372, ts.DiagnosticCategory.Suggestion, "This_import_may_be_converted_to_a_type_only_import_1372", "This import may be converted to a type-only import."),
43564356
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
43574357
Convert_all_imports_not_used_as_a_value_to_type_only_imports: diag(1374, ts.DiagnosticCategory.Message, "Convert_all_imports_not_used_as_a_value_to_type_only_imports_1374", "Convert all imports not used as a value to type-only imports"),
@@ -21052,7 +21052,7 @@ var ts;
2105221052
description: ts.Diagnostics.Import_emit_helpers_from_tslib
2105321053
},
2105421054
{
21055-
name: "importsNotUsedAsValue",
21055+
name: "importsNotUsedAsValues",
2105621056
type: ts.createMapFromTemplate({
2105721057
remove: 0,
2105821058
preserve: 1,
@@ -32887,7 +32887,7 @@ var ts;
3288732887
getTypeWithFacts(type, 524288) :
3288832888
type;
3288932889
}
32890-
return getUnionType([getTypeWithFacts(type, 524288), checkDeclarationInitializer(declaration)], 2);
32890+
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288), checkDeclarationInitializer(declaration)], 2));
3289132891
}
3289232892
function getTypeForDeclarationFromJSDocComment(declaration) {
3289332893
var jsdocType = ts.getJSDocType(declaration);
@@ -32973,7 +32973,7 @@ var ts;
3297332973
}
3297432974
}
3297532975
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
32976-
var type = checkDeclarationInitializer(declaration);
32976+
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
3297732977
return addOptionality(type, isOptional);
3297832978
}
3297932979
if (ts.isJsxAttribute(declaration)) {
@@ -33173,7 +33173,8 @@ var ts;
3317333173
}
3317433174
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
3317533175
if (element.initializer) {
33176-
return addOptionality(checkDeclarationInitializer(element));
33176+
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, true, false) : unknownType;
33177+
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
3317733178
}
3317833179
if (ts.isBindingPattern(element.name)) {
3317933180
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -44423,9 +44424,10 @@ var ts;
4442344424
}
4442444425
}
4442544426
function getContextualTypeForBindingElement(declaration) {
44426-
var parentDeclaration = declaration.parent.parent;
44427+
var parent = declaration.parent.parent;
4442744428
var name = declaration.propertyName || declaration.name;
44428-
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
44429+
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
44430+
parent.kind !== 191 && parent.initializer && checkDeclarationInitializer(parent);
4442944431
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
4443044432
var nameType = getLiteralTypeFromPropertyName(name);
4443144433
if (isTypeUsableAsPropertyName(nameType)) {
@@ -49397,27 +49399,13 @@ var ts;
4939749399
node = ts.skipParentheses(node);
4939849400
return node.kind === 199 || node.kind === 217;
4939949401
}
49400-
function checkDeclarationInitializer(declaration) {
49402+
function checkDeclarationInitializer(declaration, contextualType) {
4940149403
var initializer = ts.getEffectiveInitializer(declaration);
49402-
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
49403-
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 &&
49404+
var type = getQuickTypeOfExpression(initializer) ||
49405+
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, undefined, 0) : checkExpressionCached(initializer));
49406+
return ts.isParameter(declaration) && declaration.name.kind === 190 &&
4940449407
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
4940549408
padTupleType(type, declaration.name) : type;
49406-
var widened = ts.getCombinedNodeFlags(declaration) & 2 ||
49407-
ts.isDeclarationReadonly(declaration) ||
49408-
isTypeAssertion(initializer) ||
49409-
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
49410-
if (ts.isInJSFile(declaration)) {
49411-
if (widened.flags & 98304) {
49412-
reportImplicitAny(declaration, anyType);
49413-
return anyType;
49414-
}
49415-
else if (isEmptyArrayLiteralType(widened)) {
49416-
reportImplicitAny(declaration, anyArrayType);
49417-
return anyArrayType;
49418-
}
49419-
}
49420-
return widened;
4942149409
}
4942249410
function padTupleType(type, pattern) {
4942349411
var patternElements = pattern.elements;
@@ -49434,6 +49422,20 @@ var ts;
4943449422
}
4943549423
return createTupleType(elementTypes, type.target.minLength, false, type.target.readonly);
4943649424
}
49425+
function widenTypeInferredFromInitializer(declaration, type) {
49426+
var widened = ts.getCombinedNodeFlags(declaration) & 2 || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
49427+
if (ts.isInJSFile(declaration)) {
49428+
if (widened.flags & 98304) {
49429+
reportImplicitAny(declaration, anyType);
49430+
return anyType;
49431+
}
49432+
else if (isEmptyArrayLiteralType(widened)) {
49433+
reportImplicitAny(declaration, anyArrayType);
49434+
return anyArrayType;
49435+
}
49436+
}
49437+
return widened;
49438+
}
4943749439
function isLiteralOfContextualType(candidateType, contextualType) {
4943849440
if (contextualType) {
4943949441
if (contextualType.flags & 3145728) {
@@ -53524,9 +53526,9 @@ var ts;
5352453526
!statement.importClause.isTypeOnly &&
5352553527
importClauseContainsReferencedImport(statement.importClause) &&
5352653528
!isReferencedAliasDeclaration(statement.importClause, true)) {
53527-
var isError = compilerOptions.importsNotUsedAsValue === 2;
53529+
var isError = compilerOptions.importsNotUsedAsValues === 2;
5352853530
errorOrSuggestion(isError, statement, isError
53529-
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
53531+
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
5353053532
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
5353153533
}
5353253534
}
@@ -64410,8 +64412,8 @@ var ts;
6441064412
}
6441164413
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
6441264414
return importClause ||
64413-
compilerOptions.importsNotUsedAsValue === 1 ||
64414-
compilerOptions.importsNotUsedAsValue === 2
64415+
compilerOptions.importsNotUsedAsValues === 1 ||
64416+
compilerOptions.importsNotUsedAsValues === 2
6441564417
? ts.updateImportDeclaration(node, undefined, undefined, importClause, node.moduleSpecifier)
6441664418
: undefined;
6441764419
}
@@ -64476,7 +64478,7 @@ var ts;
6447664478
function visitImportEqualsDeclaration(node) {
6447764479
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
6447864480
var isReferenced = resolver.isReferencedAliasDeclaration(node);
64479-
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1) {
64481+
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1) {
6448064482
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(undefined, undefined, undefined, node.moduleReference.expression), node), node);
6448164483
}
6448264484
return isReferenced ? ts.visitEachChild(node, visitor, context) : undefined;

0 commit comments

Comments
 (0)