javascript - TypeScript Interface not working as I expected -
so right now, i'm trying make small modular web application. using typescript, quite new to.
in code, i:
- define structure of interface (
programlist
) - i create object 1 property (
programlist
) of typeprograminfo
- i define
programlist
1 array item usingprogramlist
interface.
here code:
interface programinfo { path:string; name:string; pkgname:string[]; start?:string[]; cli?:string[]; } let program = { programlist: programinfo[] }; program.programlist = [ { path: "/default_programs/wospman", name: "wospman (webos package manager)", pkgname: ["com", "webos", "wospman"], start: ["wospman", "wospm"], cli: ["wospman"] } ];
my ide (jetbrains webstorm), keeps giving me typescript compile errors:
ts2304: cannot find name
programinfo`
although defined programinfo
on first few lines.
when do:
let program = { programlist: programinfo[] };
you declare object program
property programlist
. trying assign array of interfaces property, not make sense. can this:
let program: {programlist: programinfo[]} = { programlist: [] };
or this:
interface program { programlist: programinfo[]; } let program: program = { programlist: [] };
Comments
Post a Comment