Update LKG.

This commit is contained in:
Daniel Rosenwasser
2020-01-06 14:05:17 -08:00
parent 68465f88cf
commit 20c0e8b7aa
10 changed files with 249 additions and 222 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ declare var Function: FunctionConstructor;
/**
* Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
*/
type ThisParameterType<T> = T extends (this: unknown, ...args: any[]) => any ? unknown : T extends (this: infer U, ...args: any[]) => any ? U : unknown;
type ThisParameterType<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown;
/**
* Removes the 'this' parameter from a function type.
+32 -30
View File
@@ -4351,7 +4351,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0,
preserve: 1,
@@ -32887,7 +32887,7 @@ var ts;
getTypeWithFacts(type, 524288) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288), checkDeclarationInitializer(declaration)], 2);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288), checkDeclarationInitializer(declaration)], 2));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -32973,7 +32973,7 @@ var ts;
}
}
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -33173,7 +33173,8 @@ var ts;
}
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, true, false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -44423,9 +44424,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -49397,27 +49399,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 || node.kind === 217;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, undefined, 0) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -49434,6 +49422,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728) {
@@ -53524,9 +53526,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2;
var isError = compilerOptions.importsNotUsedAsValues === 2;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -64410,8 +64412,8 @@ var ts;
}
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 ||
compilerOptions.importsNotUsedAsValue === 2
compilerOptions.importsNotUsedAsValues === 1 ||
compilerOptions.importsNotUsedAsValues === 2
? ts.updateImportDeclaration(node, undefined, undefined, importClause, node.moduleSpecifier)
: undefined;
}
@@ -64476,7 +64478,7 @@ var ts;
function visitImportEqualsDeclaration(node) {
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(undefined, undefined, undefined, node.moduleReference.expression), node), node);
}
return isReferenced ? ts.visitEachChild(node, visitor, context) : undefined;
+42 -37
View File
@@ -3976,12 +3976,12 @@ var ts;
JsxEmit[JsxEmit["React"] = 2] = "React";
JsxEmit[JsxEmit["ReactNative"] = 3] = "ReactNative";
})(JsxEmit = ts.JsxEmit || (ts.JsxEmit = {}));
var ImportsNotUsedAsValue;
(function (ImportsNotUsedAsValue) {
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Remove"] = 0] = "Remove";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Preserve"] = 1] = "Preserve";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Error"] = 2] = "Error";
})(ImportsNotUsedAsValue = ts.ImportsNotUsedAsValue || (ts.ImportsNotUsedAsValue = {}));
var importsNotUsedAsValues;
(function (importsNotUsedAsValues) {
importsNotUsedAsValues[importsNotUsedAsValues["Remove"] = 0] = "Remove";
importsNotUsedAsValues[importsNotUsedAsValues["Preserve"] = 1] = "Preserve";
importsNotUsedAsValues[importsNotUsedAsValues["Error"] = 2] = "Error";
})(importsNotUsedAsValues = ts.importsNotUsedAsValues || (ts.importsNotUsedAsValues = {}));
var NewLineKind;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
@@ -6756,7 +6756,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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"),
@@ -26024,7 +26024,7 @@ var ts;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0 /* Remove */,
preserve: 1 /* Preserve */,
@@ -39873,7 +39873,7 @@ var ts;
getTypeWithFacts(type, 524288 /* NEUndefined */) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -39977,7 +39977,7 @@ var ts;
// Use the type of the initializer expression if one is present and the declaration is
// not a parameter of a contextually typed function
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -40191,7 +40191,11 @@ var ts;
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
// The type implied by a binding pattern is independent of context, so we check the initializer with no
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -53130,9 +53134,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -58949,27 +58954,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 /* TypeAssertionExpression */ || node.kind === 217 /* AsExpression */;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -58986,6 +58977,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, /*hasRestElement*/ false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -63874,9 +63879,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2 /* Error */;
var isError = compilerOptions.importsNotUsedAsValues === 2 /* Error */;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -76858,7 +76863,7 @@ var ts;
}
}
/**
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValue` is not 'preserve'.
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValues` is not 'preserve'.
*
* @param node The import declaration node.
*/
@@ -76875,8 +76880,8 @@ var ts;
// Elide the declaration if the import clause was elided.
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValue === 2 /* Error */
compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValues === 2 /* Error */
? ts.updateImportDeclaration(node,
/*decorators*/ undefined,
/*modifiers*/ undefined, importClause, node.moduleSpecifier)
@@ -77007,7 +77012,7 @@ var ts;
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1 /* Preserve */) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* Preserve */) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
+2 -2
View File
@@ -2651,7 +2651,7 @@ declare namespace ts {
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
importHelpers?: boolean;
importsNotUsedAsValue?: ImportsNotUsedAsValue;
importsNotUsedAsValues?: importsNotUsedAsValues;
inlineSourceMap?: boolean;
inlineSources?: boolean;
isolatedModules?: boolean;
@@ -2750,7 +2750,7 @@ declare namespace ts {
React = 2,
ReactNative = 3
}
export enum ImportsNotUsedAsValue {
export enum importsNotUsedAsValues {
Remove = 0,
Preserve = 1,
Error = 2
+42 -37
View File
@@ -4126,12 +4126,12 @@ var ts;
JsxEmit[JsxEmit["React"] = 2] = "React";
JsxEmit[JsxEmit["ReactNative"] = 3] = "ReactNative";
})(JsxEmit = ts.JsxEmit || (ts.JsxEmit = {}));
var ImportsNotUsedAsValue;
(function (ImportsNotUsedAsValue) {
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Remove"] = 0] = "Remove";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Preserve"] = 1] = "Preserve";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Error"] = 2] = "Error";
})(ImportsNotUsedAsValue = ts.ImportsNotUsedAsValue || (ts.ImportsNotUsedAsValue = {}));
var importsNotUsedAsValues;
(function (importsNotUsedAsValues) {
importsNotUsedAsValues[importsNotUsedAsValues["Remove"] = 0] = "Remove";
importsNotUsedAsValues[importsNotUsedAsValues["Preserve"] = 1] = "Preserve";
importsNotUsedAsValues[importsNotUsedAsValues["Error"] = 2] = "Error";
})(importsNotUsedAsValues = ts.importsNotUsedAsValues || (ts.importsNotUsedAsValues = {}));
var NewLineKind;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
@@ -6906,7 +6906,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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"),
@@ -26174,7 +26174,7 @@ var ts;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0 /* Remove */,
preserve: 1 /* Preserve */,
@@ -40023,7 +40023,7 @@ var ts;
getTypeWithFacts(type, 524288 /* NEUndefined */) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -40127,7 +40127,7 @@ var ts;
// Use the type of the initializer expression if one is present and the declaration is
// not a parameter of a contextually typed function
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -40341,7 +40341,11 @@ var ts;
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
// The type implied by a binding pattern is independent of context, so we check the initializer with no
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -53280,9 +53284,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -59099,27 +59104,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 /* TypeAssertionExpression */ || node.kind === 217 /* AsExpression */;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -59136,6 +59127,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, /*hasRestElement*/ false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -64024,9 +64029,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2 /* Error */;
var isError = compilerOptions.importsNotUsedAsValues === 2 /* Error */;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -77008,7 +77013,7 @@ var ts;
}
}
/**
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValue` is not 'preserve'.
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValues` is not 'preserve'.
*
* @param node The import declaration node.
*/
@@ -77025,8 +77030,8 @@ var ts;
// Elide the declaration if the import clause was elided.
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValue === 2 /* Error */
compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValues === 2 /* Error */
? ts.updateImportDeclaration(node,
/*decorators*/ undefined,
/*modifiers*/ undefined, importClause, node.moduleSpecifier)
@@ -77157,7 +77162,7 @@ var ts;
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1 /* Preserve */) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* Preserve */) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
+2 -2
View File
@@ -2651,7 +2651,7 @@ declare namespace ts {
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
importHelpers?: boolean;
importsNotUsedAsValue?: ImportsNotUsedAsValue;
importsNotUsedAsValues?: importsNotUsedAsValues;
inlineSourceMap?: boolean;
inlineSources?: boolean;
isolatedModules?: boolean;
@@ -2750,7 +2750,7 @@ declare namespace ts {
React = 2,
ReactNative = 3
}
export enum ImportsNotUsedAsValue {
export enum importsNotUsedAsValues {
Remove = 0,
Preserve = 1,
Error = 2
+42 -37
View File
@@ -4115,12 +4115,12 @@ var ts;
JsxEmit[JsxEmit["React"] = 2] = "React";
JsxEmit[JsxEmit["ReactNative"] = 3] = "ReactNative";
})(JsxEmit = ts.JsxEmit || (ts.JsxEmit = {}));
var ImportsNotUsedAsValue;
(function (ImportsNotUsedAsValue) {
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Remove"] = 0] = "Remove";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Preserve"] = 1] = "Preserve";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Error"] = 2] = "Error";
})(ImportsNotUsedAsValue = ts.ImportsNotUsedAsValue || (ts.ImportsNotUsedAsValue = {}));
var importsNotUsedAsValues;
(function (importsNotUsedAsValues) {
importsNotUsedAsValues[importsNotUsedAsValues["Remove"] = 0] = "Remove";
importsNotUsedAsValues[importsNotUsedAsValues["Preserve"] = 1] = "Preserve";
importsNotUsedAsValues[importsNotUsedAsValues["Error"] = 2] = "Error";
})(importsNotUsedAsValues = ts.importsNotUsedAsValues || (ts.importsNotUsedAsValues = {}));
var NewLineKind;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
@@ -6895,7 +6895,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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"),
@@ -26163,7 +26163,7 @@ var ts;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0 /* Remove */,
preserve: 1 /* Preserve */,
@@ -40012,7 +40012,7 @@ var ts;
getTypeWithFacts(type, 524288 /* NEUndefined */) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -40116,7 +40116,7 @@ var ts;
// Use the type of the initializer expression if one is present and the declaration is
// not a parameter of a contextually typed function
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -40330,7 +40330,11 @@ var ts;
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
// The type implied by a binding pattern is independent of context, so we check the initializer with no
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -53269,9 +53273,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -59088,27 +59093,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 /* TypeAssertionExpression */ || node.kind === 217 /* AsExpression */;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -59125,6 +59116,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, /*hasRestElement*/ false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -64013,9 +64018,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2 /* Error */;
var isError = compilerOptions.importsNotUsedAsValues === 2 /* Error */;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -76997,7 +77002,7 @@ var ts;
}
}
/**
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValue` is not 'preserve'.
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValues` is not 'preserve'.
*
* @param node The import declaration node.
*/
@@ -77014,8 +77019,8 @@ var ts;
// Elide the declaration if the import clause was elided.
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValue === 2 /* Error */
compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValues === 2 /* Error */
? ts.updateImportDeclaration(node,
/*decorators*/ undefined,
/*modifiers*/ undefined, importClause, node.moduleSpecifier)
@@ -77146,7 +77151,7 @@ var ts;
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1 /* Preserve */) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* Preserve */) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
+2 -2
View File
@@ -2651,7 +2651,7 @@ declare namespace ts {
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
importHelpers?: boolean;
importsNotUsedAsValue?: ImportsNotUsedAsValue;
importsNotUsedAsValues?: importsNotUsedAsValues;
inlineSourceMap?: boolean;
inlineSources?: boolean;
isolatedModules?: boolean;
@@ -2750,7 +2750,7 @@ declare namespace ts {
React = 2,
ReactNative = 3
}
export enum ImportsNotUsedAsValue {
export enum importsNotUsedAsValues {
Remove = 0,
Preserve = 1,
Error = 2
+42 -37
View File
@@ -4115,12 +4115,12 @@ var ts;
JsxEmit[JsxEmit["React"] = 2] = "React";
JsxEmit[JsxEmit["ReactNative"] = 3] = "ReactNative";
})(JsxEmit = ts.JsxEmit || (ts.JsxEmit = {}));
var ImportsNotUsedAsValue;
(function (ImportsNotUsedAsValue) {
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Remove"] = 0] = "Remove";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Preserve"] = 1] = "Preserve";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Error"] = 2] = "Error";
})(ImportsNotUsedAsValue = ts.ImportsNotUsedAsValue || (ts.ImportsNotUsedAsValue = {}));
var importsNotUsedAsValues;
(function (importsNotUsedAsValues) {
importsNotUsedAsValues[importsNotUsedAsValues["Remove"] = 0] = "Remove";
importsNotUsedAsValues[importsNotUsedAsValues["Preserve"] = 1] = "Preserve";
importsNotUsedAsValues[importsNotUsedAsValues["Error"] = 2] = "Error";
})(importsNotUsedAsValues = ts.importsNotUsedAsValues || (ts.importsNotUsedAsValues = {}));
var NewLineKind;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
@@ -6895,7 +6895,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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"),
@@ -26163,7 +26163,7 @@ var ts;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0 /* Remove */,
preserve: 1 /* Preserve */,
@@ -40012,7 +40012,7 @@ var ts;
getTypeWithFacts(type, 524288 /* NEUndefined */) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -40116,7 +40116,7 @@ var ts;
// Use the type of the initializer expression if one is present and the declaration is
// not a parameter of a contextually typed function
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -40330,7 +40330,11 @@ var ts;
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
// The type implied by a binding pattern is independent of context, so we check the initializer with no
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -53269,9 +53273,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -59088,27 +59093,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 /* TypeAssertionExpression */ || node.kind === 217 /* AsExpression */;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -59125,6 +59116,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, /*hasRestElement*/ false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -64013,9 +64018,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2 /* Error */;
var isError = compilerOptions.importsNotUsedAsValues === 2 /* Error */;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -76997,7 +77002,7 @@ var ts;
}
}
/**
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValue` is not 'preserve'.
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValues` is not 'preserve'.
*
* @param node The import declaration node.
*/
@@ -77014,8 +77019,8 @@ var ts;
// Elide the declaration if the import clause was elided.
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValue === 2 /* Error */
compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValues === 2 /* Error */
? ts.updateImportDeclaration(node,
/*decorators*/ undefined,
/*modifiers*/ undefined, importClause, node.moduleSpecifier)
@@ -77146,7 +77151,7 @@ var ts;
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1 /* Preserve */) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* Preserve */) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
+42 -37
View File
@@ -3965,12 +3965,12 @@ var ts;
JsxEmit[JsxEmit["React"] = 2] = "React";
JsxEmit[JsxEmit["ReactNative"] = 3] = "ReactNative";
})(JsxEmit = ts.JsxEmit || (ts.JsxEmit = {}));
var ImportsNotUsedAsValue;
(function (ImportsNotUsedAsValue) {
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Remove"] = 0] = "Remove";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Preserve"] = 1] = "Preserve";
ImportsNotUsedAsValue[ImportsNotUsedAsValue["Error"] = 2] = "Error";
})(ImportsNotUsedAsValue = ts.ImportsNotUsedAsValue || (ts.ImportsNotUsedAsValue = {}));
var importsNotUsedAsValues;
(function (importsNotUsedAsValues) {
importsNotUsedAsValues[importsNotUsedAsValues["Remove"] = 0] = "Remove";
importsNotUsedAsValues[importsNotUsedAsValues["Preserve"] = 1] = "Preserve";
importsNotUsedAsValues[importsNotUsedAsValues["Error"] = 2] = "Error";
})(importsNotUsedAsValues = ts.importsNotUsedAsValues || (ts.importsNotUsedAsValues = {}));
var NewLineKind;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
@@ -6745,7 +6745,7 @@ var ts;
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"),
Did_you_mean_0: diag(1369, ts.DiagnosticCategory.Message, "Did_you_mean_0_1369", "Did you mean '{0}'?"),
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'."),
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'."),
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'."),
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."),
Convert_to_type_only_import: diag(1373, ts.DiagnosticCategory.Message, "Convert_to_type_only_import_1373", "Convert to type-only import"),
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"),
@@ -26013,7 +26013,7 @@ var ts;
description: ts.Diagnostics.Import_emit_helpers_from_tslib
},
{
name: "importsNotUsedAsValue",
name: "importsNotUsedAsValues",
type: ts.createMapFromTemplate({
remove: 0 /* Remove */,
preserve: 1 /* Preserve */,
@@ -39862,7 +39862,7 @@ var ts;
getTypeWithFacts(type, 524288 /* NEUndefined */) :
type;
}
return getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */);
return widenTypeInferredFromInitializer(declaration, getUnionType([getTypeWithFacts(type, 524288 /* NEUndefined */), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
}
function getTypeForDeclarationFromJSDocComment(declaration) {
var jsdocType = ts.getJSDocType(declaration);
@@ -39966,7 +39966,7 @@ var ts;
// Use the type of the initializer expression if one is present and the declaration is
// not a parameter of a contextually typed function
if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) {
var type = checkDeclarationInitializer(declaration);
var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
return addOptionality(type, isOptional);
}
if (ts.isJsxAttribute(declaration)) {
@@ -40180,7 +40180,11 @@ var ts;
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element, includePatternInType, reportErrors) {
if (element.initializer) {
return addOptionality(checkDeclarationInitializer(element));
// The type implied by a binding pattern is independent of context, so we check the initializer with no
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -53119,9 +53123,10 @@ var ts;
}
}
function getContextualTypeForBindingElement(declaration) {
var parentDeclaration = declaration.parent.parent;
var parent = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
parent.kind !== 191 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
var nameType = getLiteralTypeFromPropertyName(name);
if (isTypeUsableAsPropertyName(nameType)) {
@@ -58938,27 +58943,13 @@ var ts;
node = ts.skipParentheses(node);
return node.kind === 199 /* TypeAssertionExpression */ || node.kind === 217 /* AsExpression */;
}
function checkDeclarationInitializer(declaration) {
function checkDeclarationInitializer(declaration, contextualType) {
var initializer = ts.getEffectiveInitializer(declaration);
var type = getQuickTypeOfExpression(initializer) || checkExpressionCached(initializer);
var padded = ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
var type = getQuickTypeOfExpression(initializer) ||
(contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
return ts.isParameter(declaration) && declaration.name.kind === 190 /* ArrayBindingPattern */ &&
isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
padTupleType(type, declaration.name) : type;
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ ||
ts.isDeclarationReadonly(declaration) ||
isTypeAssertion(initializer) ||
isLiteralOfContextualType(padded, getContextualType(initializer)) ? padded : getWidenedLiteralType(padded);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function padTupleType(type, pattern) {
var patternElements = pattern.elements;
@@ -58975,6 +58966,20 @@ var ts;
}
return createTupleType(elementTypes, type.target.minLength, /*hasRestElement*/ false, type.target.readonly);
}
function widenTypeInferredFromInitializer(declaration, type) {
var widened = ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || ts.isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
if (ts.isInJSFile(declaration)) {
if (widened.flags & 98304 /* Nullable */) {
reportImplicitAny(declaration, anyType);
return anyType;
}
else if (isEmptyArrayLiteralType(widened)) {
reportImplicitAny(declaration, anyArrayType);
return anyArrayType;
}
}
return widened;
}
function isLiteralOfContextualType(candidateType, contextualType) {
if (contextualType) {
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
@@ -63863,9 +63868,9 @@ var ts;
!statement.importClause.isTypeOnly &&
importClauseContainsReferencedImport(statement.importClause) &&
!isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true)) {
var isError = compilerOptions.importsNotUsedAsValue === 2 /* Error */;
var isError = compilerOptions.importsNotUsedAsValues === 2 /* Error */;
errorOrSuggestion(isError, statement, isError
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValue_is_set_to_error
? ts.Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error
: ts.Diagnostics.This_import_may_be_converted_to_a_type_only_import);
}
}
@@ -76847,7 +76852,7 @@ var ts;
}
}
/**
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValue` is not 'preserve'.
* Visits an import declaration, eliding it if it is not referenced and `importsNotUsedAsValues` is not 'preserve'.
*
* @param node The import declaration node.
*/
@@ -76864,8 +76869,8 @@ var ts;
// Elide the declaration if the import clause was elided.
var importClause = ts.visitNode(node.importClause, visitImportClause, ts.isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValue === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValue === 2 /* Error */
compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
compilerOptions.importsNotUsedAsValues === 2 /* Error */
? ts.updateImportDeclaration(node,
/*decorators*/ undefined,
/*modifiers*/ undefined, importClause, node.moduleSpecifier)
@@ -76996,7 +77001,7 @@ var ts;
if (ts.isExternalModuleImportEqualsDeclaration(node)) {
var isReferenced = resolver.isReferencedAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValue === 1 /* Preserve */) {
if (!isReferenced && compilerOptions.importsNotUsedAsValues === 1 /* Preserve */) {
return ts.setOriginalNode(ts.setTextRange(ts.createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,