0

I had a problem with generic types. I have a user defined type(interface) like this:

IList1: {  
          prop1: string,  
          prop2: number,  
          prop3: string  
          .  
          .  
          . 
       }

IList2:...
IList3:...

and after some serverside response, I get response in the type of Array<Array<,IListx>>. So I tried to create a function like this:

function fun<T>(args:T):Array<Array<T>> {
  return Array<Array<typeof args>>;
}

and variables like this:

let a:fun<IList1> = ...;
let b:fun<IList2> = ...;
let x:fun<IListx> = ...;

This didn't work. Also I'm not sure this is the correct way of creating a generic type. I know I did something wrong but couldn't find the proper solution. Any help would be appreciated.

0

1 Answer 1

1

After some trials, I think I found a way by both defining and initializing:

function fun<T>():Array<Array<T>> {
  return Array<Array<T>>();
}


let a= fun<IList1>();
let b= fun<IList2>();

worked as expected. I don't know if there are possible better solutions.

Sign up to request clarification or add additional context in comments.

Comments

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.