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?

1
  • I think what you are looking for is Object.assign(target, param1, ...) Commented Nov 8, 2017 at 7:24

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.