mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-01 02:02:45 -05:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user