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 type programinfo
  • i define programlist 1 array item using programlist 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 nameprograminfo`

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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -