fix(40994): change type for optional properties (#41011)

This commit is contained in:
Oleksandr T
2020-10-27 10:05:40 -07:00
committed by GitHub
parent 292b778204
commit 3754bb4455
7 changed files with 124 additions and 13 deletions
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
// @strict: true
////class A {
//// /*a*/foo?: string;/*b*/
////}
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Generate 'get' and 'set' accessors",
actionName: "Generate 'get' and 'set' accessors",
actionDescription: "Generate 'get' and 'set' accessors",
newContent:
`class A {
private /*RENAME*/_foo?: string | undefined;
public get foo(): string | undefined {
return this._foo;
}
public set foo(value: string | undefined) {
this._foo = value;
}
}`
});
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
// @strict: true
////class A {
//// /*a*/foo?: string | undefined;/*b*/
////}
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Generate 'get' and 'set' accessors",
actionName: "Generate 'get' and 'set' accessors",
actionDescription: "Generate 'get' and 'set' accessors",
newContent:
`class A {
private /*RENAME*/_foo?: string | undefined;
public get foo(): string | undefined {
return this._foo;
}
public set foo(value: string | undefined) {
this._foo = value;
}
}`
});
@@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
// @strict: true
////type Foo = undefined | null;
////class A {
//// /*a*/foo?: string | Foo;/*b*/
////}
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Generate 'get' and 'set' accessors",
actionName: "Generate 'get' and 'set' accessors",
actionDescription: "Generate 'get' and 'set' accessors",
newContent:
`type Foo = undefined | null;
class A {
private /*RENAME*/_foo?: string | Foo;
public get foo(): string | Foo {
return this._foo;
}
public set foo(value: string | Foo) {
this._foo = value;
}
}`
});
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
// @strict: true
////class A {
//// /*a*/foo?: any;/*b*/
////}
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Generate 'get' and 'set' accessors",
actionName: "Generate 'get' and 'set' accessors",
actionDescription: "Generate 'get' and 'set' accessors",
newContent:
`class A {
private /*RENAME*/_foo?: any;
public get foo(): any {
return this._foo;
}
public set foo(value: any) {
this._foo = value;
}
}`
});