Skip to content

Fix 4628: add compiler option for non-check static member in inheritance #39699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34355,7 +34355,7 @@ namespace ts {
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
issueMemberSpecificError(node, typeWithThis, baseWithThis, Diagnostics.Class_0_incorrectly_extends_base_class_1);
}
else {
else if(!compilerOptions.looseClassInheritanceStaticCheck) {
// Report static side error only when instance type is assignable
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ namespace ts {
},

// Advanced
{
name: "looseClassInheritanceStaticCheck",
type: "boolean",
category: Diagnostics.Advanced_Options,
description: Diagnostics.Not_check_static_member_type_whether_incompatible_with_base_in_inheritance_class
},
{
name: "jsxFactory",
type: "string",
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4652,7 +4652,10 @@
"code": 6385,
"reportsDeprecated": true
},

"Not check static member type whether incompatible with base in inheritance class": {
"category": "Message",
"code": 6386
},
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
"code": 6500
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5689,6 +5689,7 @@ namespace ts {
/*@internal*/listFiles?: boolean;
/*@internal*/listFilesOnly?: boolean;
locale?: string;
looseClassInheritanceStaticCheck?: boolean;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind;
Expand Down
1 change: 1 addition & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,7 @@ namespace ts.server.protocol {
jsx?: JsxEmit | ts.JsxEmit;
lib?: string[];
locale?: string;
looseClassInheritanceStaticCheck?: boolean;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind | ts.ModuleKind;
Expand Down
4 changes: 4 additions & 0 deletions src/testRunner/unittests/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ var x = 0;`, {
options: { compilerOptions: { locale: "en-us" }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Supports setting 'looseClassInheritanceStaticCheck'", "x;", {
options: { compilerOptions: { looseClassInheritanceStaticCheck: true }, fileName: "input.js", reportDiagnostics: true }
});

transpilesCorrectly("Supports setting 'module'", "x;", {
options: { compilerOptions: { module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true }
});
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,7 @@ declare namespace ts {
keyofStringsOnly?: boolean;
lib?: string[];
locale?: string;
looseClassInheritanceStaticCheck?: boolean;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind;
Expand Down Expand Up @@ -8921,6 +8922,7 @@ declare namespace ts.server.protocol {
jsx?: JsxEmit | ts.JsxEmit;
lib?: string[];
locale?: string;
looseClassInheritanceStaticCheck?: boolean;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind | ts.ModuleKind;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,7 @@ declare namespace ts {
keyofStringsOnly?: boolean;
lib?: string[];
locale?: string;
looseClassInheritanceStaticCheck?: boolean;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
module?: ModuleKind;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"looseClassInheritanceStaticCheck": true
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.