Fixes an issue with type naming for TypeScript input where the name ends up as default if the first type in the file is export default.
Replaces the topLevelName with the name from the corresponding ref type
Motivation and Context
Fixes #1295
Input File
/** #TopLevel */
export default class AddressBook {
/**
* A dictionary of Contacts, indexed by unique ID
*/
contacts: { [id: string]: Contact };
}
class Contact {
firstName: string;
lastName?: string;
birthday?: Date;
title?: "Mr." | "Mrs." | "Ms." | "Prof.";
emails: string[];
phones: PhoneNumber[];
/** @TJS-type integer */
highScore: number;
}
/**
* A Contact's phone number.
*/
class PhoneNumber {
number: string;
/** An optional label (e.g. "mobile") */
label?: string;
}
Previous Behaviour / Output
import 'dart:convert';
class Default {
Map<String, Contact> contacts;
Default({
this.contacts,
});
factory Default.fromJson(String str) => Default.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory Default.fromMap(Map<String, dynamic> json) => new Default(
contacts: new Map.from(json["contacts"]).map((k, v) => new MapEntry<String, Contact>(k, Contact.fromMap(v))),
);
Map<String, dynamic> toMap() => {
"contacts": new Map.from(contacts).map((k, v) => new MapEntry<String, dynamic>(k, v.toMap())),
};
}
Description
Fixes an issue with type naming for TypeScript input where the name ends up as
default
if the first type in the file isexport default
. Replaces thetopLevelName
with the name from the corresponding ref typeMotivation and Context
Fixes #1295
Input File
Previous Behaviour / Output
New Behaviour / Output
How Has This Been Tested?
TBD on how we should test
quicktype-typescript-input
Screenshots (if appropriate):