Do not add undefined to parameter properties

They are actually properties, so don't get undefined added when they
have an initialiser.

Also update baselines
This commit is contained in:
Nathan Shively-Sanders
2016-11-04 08:22:55 -07:00
parent 286845c6c5
commit 00ff0e5bb8
3 changed files with 8 additions and 6 deletions

View File

@@ -3206,7 +3206,9 @@ namespace ts {
// Use the type of the initializer expression if one is present
if (declaration.initializer) {
const type = checkDeclarationInitializer(declaration);
const isOptional = declaration.questionToken || (declaration.initializer && declaration.kind === SyntaxKind.Parameter);
// initialized parameters (but not parameter properties) are optional
const isOptional = declaration.questionToken ||
(declaration.kind === SyntaxKind.Parameter && !(getModifierFlags(declaration) & ModifierFlags.ParameterPropertyModifier));
return addOptionality(type, isOptional && includeOptionality);
}

View File

@@ -128,11 +128,11 @@ interface Foo {
declare function test1(x: Foo): void;
declare class Bar {
d: number;
e: number | undefined;
e: number;
a: number;
b?: number;
c?: number | undefined;
constructor(d?: number, e?: number | undefined);
constructor(d?: number, e?: number);
f(): number;
g?(): number;
h?(): number;

View File

@@ -87,7 +87,7 @@ class Bar {
constructor(public d?: number, public e = 10) {}
>d : number | undefined
>e : number | undefined
>e : number
>10 : 10
f() {
@@ -133,9 +133,9 @@ function test2(x: Bar) {
>d : number | undefined
x.e;
>x.e : number | undefined
>x.e : number
>x : Bar
>e : number | undefined
>e : number
x.f;
>x.f : () => number