javascript - TypeScript: Creating an empty typed container array -
i creating simple logic game called "three of crime" in typescript.
when trying pre-allocated typed array in typescript, tried this:
var arr = criminal[];
which gave error "check format of expression term" .
also tried doing this
var arr : criminal = [];
and produced "cannot convert any[] 'criminal'
what 'typescript' way this?
the issue of correctly pre-allocating typed array in typescript obscured due array literal syntax, wasn't intuitive first thought.
the correct way be
var arr : criminal[] = [];
this give correctly typed, empty array stored in variable 'arr'
hope helps others!
Comments
Post a Comment