mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(40994): change type for optional properties (#41011)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}`
|
||||
});
|
||||
Reference in New Issue
Block a user