I have some JSON containing anonymous objects coming to my client-side. Is there some built-in mechanism or external library for converting these anonymous objects into strongly-typed TypeScript objects? Is there something like AutoMapper for doing this?
My objects are complex types, with complex types as properties.
Get some sample data and place it in a .ts file:
Run
tsc --declaration yourFile.tsNow you'll have
yourFile.d.ts:Replace
declare var people:withinterface Person, remove the trailing[], and (optionally) remove the quotes: