0

I'm new to typescript, want to convert the following values to an object so that I may reuse them in the form of an object variable.

 abc.create ( param1, {
            main: this.ODDD,
            filter: this.RLL
        }, param3)

I'm trying to declare a variable 'param2' so that I may use the second parameter which is of type Object so that I may use it at other places. I'm trying to do it like this but can't work out.

 var param2: Object = {
        main: string, 
        filter: string
    };

but it doesn't allow me to create this or assign values, the error is: "string only refers to a type but it is used as a value here".

Have tried this and this link but didn't work.

Any ideas?

sam
  • 391
  • 1
  • 5
  • 19

1 Answers1

0

You need to create interfaces to achieve the same

interface Param {
     main: string,
     filter: string, 
}

let abc = {
   create (param1, param2: Param, param3) {
        //your code
   } 
}

let param2: Param = <Param>{
  main: "string content",
  filter: "string content2"
}

abc.create(param1, param2, param3);
Max Gaurav
  • 1,835
  • 2
  • 13
  • 26
  • declaring an interface didn't work for me as I wanted to declare a variable first and assign the value later. I changed that to class and it worked: let param2: Param = new Param(); param2.main = "abc"; param2.filter = "anything"; – sam Nov 09 '17 at 00:29