diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 815b29454fd4b..f97d3a0a387e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index f5cb2990a593a..3e6eeafdbbe9e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -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", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5110ff2be8b72..242957db41910 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 67065ca804647..786e78d25944b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5689,6 +5689,7 @@ namespace ts { /*@internal*/listFiles?: boolean; /*@internal*/listFilesOnly?: boolean; locale?: string; + looseClassInheritanceStaticCheck?: boolean; mapRoot?: string; maxNodeModuleJsDepth?: number; module?: ModuleKind; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index cdeaad1a4fc22..c706c271f009b 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -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; diff --git a/src/testRunner/unittests/services/transpile.ts b/src/testRunner/unittests/services/transpile.ts index 765b4f345e644..d293ff5c4b8f6 100644 --- a/src/testRunner/unittests/services/transpile.ts +++ b/src/testRunner/unittests/services/transpile.ts @@ -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 } }); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 8442b93e4f686..13299887283f6 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2776,6 +2776,7 @@ declare namespace ts { keyofStringsOnly?: boolean; lib?: string[]; locale?: string; + looseClassInheritanceStaticCheck?: boolean; mapRoot?: string; maxNodeModuleJsDepth?: number; module?: ModuleKind; @@ -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; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3f7f682342456..0aa41552aa2ef 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2776,6 +2776,7 @@ declare namespace ts { keyofStringsOnly?: boolean; lib?: string[]; locale?: string; + looseClassInheritanceStaticCheck?: boolean; mapRoot?: string; maxNodeModuleJsDepth?: number; module?: ModuleKind; diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/looseClassInheritanceStaticCheck/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/looseClassInheritanceStaticCheck/tsconfig.json new file mode 100644 index 0000000000000..5ea7fd721e272 --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/looseClassInheritanceStaticCheck/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "looseClassInheritanceStaticCheck": true + } +} diff --git a/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.js b/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.js new file mode 100644 index 0000000000000..8394371f9081a --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.oldTranspile.js b/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.oldTranspile.js new file mode 100644 index 0000000000000..8394371f9081a --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting looseClassInheritanceStaticCheck.oldTranspile.js @@ -0,0 +1,2 @@ +x; +//# sourceMappingURL=input.js.map \ No newline at end of file