-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for TypeScript 4.3 override keyword (#1489)
* Add support for TypeScript 4.3 override keyword * Create verify tests for different output styles and TS versions
- Loading branch information
Showing
19 changed files
with
1,968 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
...t.Tests/Snapshots/ClassGenerationTests.Verify_output_style=Class_version=1.8.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
//---------------------- | ||
// <auto-generated> | ||
// </auto-generated> | ||
//---------------------- | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
export class Person implements IPerson { | ||
firstName: string; | ||
lastName: string; | ||
|
||
constructor(data?: IPerson) { | ||
if (data) { | ||
for (var property in data) { | ||
if (data.hasOwnProperty(property)) | ||
(<any>this)[property] = (<any>data)[property]; | ||
} | ||
} | ||
} | ||
|
||
init(_data?: any) { | ||
if (_data) { | ||
this.firstName = _data["FirstName"]; | ||
this.lastName = _data["LastName"]; | ||
} | ||
} | ||
|
||
static fromJS(data: any): Person { | ||
data = typeof data === 'object' ? data : {}; | ||
let result = new Person(); | ||
result.init(data); | ||
return result; | ||
} | ||
|
||
toJSON(data?: any) { | ||
data = typeof data === 'object' ? data : {}; | ||
data["FirstName"] = this.firstName; | ||
data["LastName"] = this.lastName; | ||
return data; | ||
} | ||
} | ||
|
||
export interface IPerson { | ||
firstName: string; | ||
lastName: string; | ||
} | ||
|
||
export class Student extends Person implements IStudent { | ||
study: string; | ||
|
||
constructor(data?: IStudent) { | ||
super(data); | ||
} | ||
|
||
init(_data?: any) { | ||
super.init(_data); | ||
if (_data) { | ||
this.study = _data["Study"]; | ||
} | ||
} | ||
|
||
static fromJS(data: any): Student { | ||
data = typeof data === 'object' ? data : {}; | ||
let result = new Student(); | ||
result.init(data); | ||
return result; | ||
} | ||
|
||
toJSON(data?: any) { | ||
data = typeof data === 'object' ? data : {}; | ||
data["Study"] = this.study; | ||
super.toJSON(data); | ||
return data; | ||
} | ||
} | ||
|
||
export interface IStudent extends IPerson { | ||
study: string; | ||
} | ||
|
||
export class MyClass implements IMyClass { | ||
name: string; | ||
dateOfBirth: Date; | ||
primitiveArray: number[]; | ||
primitiveDictionary: { [key: string]: number; }; | ||
dateArray: Date[]; | ||
dateDictionary: { [key: string]: Date; }; | ||
reference: Student; | ||
array: Student[]; | ||
dictionary: { [key: string]: Student; }; | ||
|
||
constructor(data?: IMyClass) { | ||
if (data) { | ||
for (var property in data) { | ||
if (data.hasOwnProperty(property)) | ||
(<any>this)[property] = (<any>data)[property]; | ||
} | ||
} | ||
if (!data) { | ||
this.name = "foo"; | ||
} | ||
} | ||
|
||
init(_data?: any) { | ||
if (_data) { | ||
this.name = _data["Name"] !== undefined ? _data["Name"] : "foo"; | ||
this.dateOfBirth = _data["DateOfBirth"] ? new Date(_data["DateOfBirth"].toString()) : <any>undefined; | ||
if (Array.isArray(_data["PrimitiveArray"])) { | ||
this.primitiveArray = [] as any; | ||
for (let item of _data["PrimitiveArray"]) | ||
this.primitiveArray.push(item); | ||
} | ||
if (_data["PrimitiveDictionary"]) { | ||
this.primitiveDictionary = {} as any; | ||
for (let key in _data["PrimitiveDictionary"]) { | ||
if (_data["PrimitiveDictionary"].hasOwnProperty(key)) | ||
(<any>this.primitiveDictionary)[key] = _data["PrimitiveDictionary"][key]; | ||
} | ||
} | ||
if (Array.isArray(_data["DateArray"])) { | ||
this.dateArray = [] as any; | ||
for (let item of _data["DateArray"]) | ||
this.dateArray.push(new Date(item)); | ||
} | ||
if (_data["DateDictionary"]) { | ||
this.dateDictionary = {} as any; | ||
for (let key in _data["DateDictionary"]) { | ||
if (_data["DateDictionary"].hasOwnProperty(key)) | ||
(<any>this.dateDictionary)[key] = _data["DateDictionary"][key] ? new Date(_data["DateDictionary"][key].toString()) : <any>undefined; | ||
} | ||
} | ||
this.reference = _data["Reference"] ? Student.fromJS(_data["Reference"]) : <any>undefined; | ||
if (Array.isArray(_data["Array"])) { | ||
this.array = [] as any; | ||
for (let item of _data["Array"]) | ||
this.array.push(Student.fromJS(item)); | ||
} | ||
if (_data["Dictionary"]) { | ||
this.dictionary = {} as any; | ||
for (let key in _data["Dictionary"]) { | ||
if (_data["Dictionary"].hasOwnProperty(key)) | ||
(<any>this.dictionary)[key] = _data["Dictionary"][key] ? Student.fromJS(_data["Dictionary"][key]) : new Student(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
static fromJS(data: any): MyClass { | ||
data = typeof data === 'object' ? data : {}; | ||
let result = new MyClass(); | ||
result.init(data); | ||
return result; | ||
} | ||
|
||
toJSON(data?: any) { | ||
data = typeof data === 'object' ? data : {}; | ||
data["Name"] = this.name; | ||
data["DateOfBirth"] = this.dateOfBirth ? this.dateOfBirth.toISOString() : <any>undefined; | ||
if (Array.isArray(this.primitiveArray)) { | ||
data["PrimitiveArray"] = []; | ||
for (let item of this.primitiveArray) | ||
data["PrimitiveArray"].push(item); | ||
} | ||
if (this.primitiveDictionary) { | ||
data["PrimitiveDictionary"] = {}; | ||
for (let key in this.primitiveDictionary) { | ||
if (this.primitiveDictionary.hasOwnProperty(key)) | ||
(<any>data["PrimitiveDictionary"])[key] = this.primitiveDictionary[key]; | ||
} | ||
} | ||
if (Array.isArray(this.dateArray)) { | ||
data["DateArray"] = []; | ||
for (let item of this.dateArray) | ||
data["DateArray"].push(item.toISOString()); | ||
} | ||
if (this.dateDictionary) { | ||
data["DateDictionary"] = {}; | ||
for (let key in this.dateDictionary) { | ||
if (this.dateDictionary.hasOwnProperty(key)) | ||
(<any>data["DateDictionary"])[key] = this.dateDictionary[key] ? this.dateDictionary[key].toISOString() : <any>undefined; | ||
} | ||
} | ||
data["Reference"] = this.reference ? this.reference.toJSON() : <any>undefined; | ||
if (Array.isArray(this.array)) { | ||
data["Array"] = []; | ||
for (let item of this.array) | ||
data["Array"].push(item.toJSON()); | ||
} | ||
if (this.dictionary) { | ||
data["Dictionary"] = {}; | ||
for (let key in this.dictionary) { | ||
if (this.dictionary.hasOwnProperty(key)) | ||
(<any>data["Dictionary"])[key] = this.dictionary[key] ? this.dictionary[key].toJSON() : <any>undefined; | ||
} | ||
} | ||
return data; | ||
} | ||
} | ||
|
||
export interface IMyClass { | ||
name: string; | ||
dateOfBirth: Date; | ||
primitiveArray: number[]; | ||
primitiveDictionary: { [key: string]: number; }; | ||
dateArray: Date[]; | ||
dateDictionary: { [key: string]: Date; }; | ||
reference: Student; | ||
array: Student[]; | ||
dictionary: { [key: string]: Student; }; | ||
} |
Oops, something went wrong.