Fix #8834: exclude paramters and variables from flag checks
This commit is contained in:
parent
8aa6a9dcd6
commit
5e49b57fea
8 changed files with 91 additions and 0 deletions
|
@ -14527,6 +14527,12 @@ namespace ts {
|
|||
}
|
||||
|
||||
function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {
|
||||
if ((left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) ||
|
||||
(left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)) {
|
||||
// Diffrences in optionality between paramters and variables are allowed.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasQuestionToken(left) !== hasQuestionToken(right)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
//// [optionalParamterAndVariableDeclaration.ts]
|
||||
class C {
|
||||
constructor(options?: number) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [optionalParamterAndVariableDeclaration.js]
|
||||
var C = (function () {
|
||||
function C(options) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
return C;
|
||||
}());
|
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts ===
|
||||
class C {
|
||||
>C : Symbol(C, Decl(optionalParamterAndVariableDeclaration.ts, 0, 0))
|
||||
|
||||
constructor(options?: number) {
|
||||
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
|
||||
|
||||
var options = (options || 0);
|
||||
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
|
||||
>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
constructor(options?: number) {
|
||||
>options : number
|
||||
|
||||
var options = (options || 0);
|
||||
>options : number
|
||||
>(options || 0) : number
|
||||
>options || 0 : number
|
||||
>options : number
|
||||
>0 : number
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts(4,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts (1 errors) ====
|
||||
|
||||
class C {
|
||||
constructor(options?: number) {
|
||||
var options = (options || 0);
|
||||
~~~~~~~
|
||||
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'.
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
//// [optionalParamterAndVariableDeclaration2.ts]
|
||||
|
||||
class C {
|
||||
constructor(options?: number) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [optionalParamterAndVariableDeclaration2.js]
|
||||
var C = (function () {
|
||||
function C(options) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
return C;
|
||||
}());
|
|
@ -0,0 +1,5 @@
|
|||
class C {
|
||||
constructor(options?: number) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
// @strictNullChecks: true
|
||||
|
||||
class C {
|
||||
constructor(options?: number) {
|
||||
var options = (options || 0);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue