javascript - JS Code convert to Typescript -


i need convert following code typescript. array objects. , want use inside class. tried use interface not proceed much. please me.

var accountmodel = {         name: 'abc account',         accounts: [             { balance: 10000, description: 'checking' },             { balance: 50000, description: 'savings' }         ]     }; 

your appreciated.

if want type checking on account model data, can use type aliases

type accountmodel = {name:string, accounts:array<account>} type account = {balance:number, description:string} 

now ide check if variable has correct content:

let acc : accountmodel = {         name: 'abc account',         accounts: [             { balance: 10000, description: 'checking' },             { balance: 50000, description: 'savings' }         ],         test: 'hello' // ide complain: 'test'                       // not assignable accountmodel  }; 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -