mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 11:46:08 -05:00
Fix46246 (#46357)
* changed error message for interface extending primitive type * moved interface check to different function * changed part of interface declaration to is extended by interface Co-authored-by: harsheetkakar <harsheetkakar@bitbucket.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -2478,7 +2478,12 @@ namespace ts {
|
||||
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
|
||||
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) {
|
||||
if (isPrimitiveTypeName(name)) {
|
||||
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
|
||||
if (isExtendedByInterface(errorLocation)) {
|
||||
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes, unescapeLeadingUnderscores(name));
|
||||
}
|
||||
else {
|
||||
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
|
||||
@@ -2499,6 +2504,17 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isExtendedByInterface(node: Node): boolean {
|
||||
const grandparent = node.parent.parent;
|
||||
const parentOfGrandparent = grandparent.parent;
|
||||
if(grandparent && parentOfGrandparent){
|
||||
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
|
||||
const isInterface = isInterfaceDeclaration(parentOfGrandparent);
|
||||
return isExtending && isInterface;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function maybeMappedType(node: Node, symbol: Symbol) {
|
||||
const container = findAncestor(node.parent, n =>
|
||||
isComputedPropertyName(n) || isPropertySignature(n) ? false : isTypeLiteralNode(n) || "quit") as TypeLiteralNode | undefined;
|
||||
|
||||
@@ -3475,6 +3475,10 @@
|
||||
"category": "Error",
|
||||
"code": 2839
|
||||
},
|
||||
"An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes": {
|
||||
"category": "Error",
|
||||
"code": 2840
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user