facebook

Error detecting incoming parameters when using generic type – how to fix it

  1. CodeMix & Angular IDE
  2.  > 
  3. Webclipse 1.x Help
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #529968 Reply

    gorand
    Participant

    Hellow!

    I need to use a variable type definition on an incoming variable type.
    See the code below – it was here to define a function call with a number key, but instead, a function with a string key and an unknown data type is defined (see the attached images)

    
    interface IObj { i:number; } // type data
    interface IEach {
    	each<TT>(p_obj:{[key:string]:TT}, p_fn:(v:TT, k:string) => void); // key string, data IObj
    	each<TT>(p_obj:{[key:number]:TT}, p_fn:(v:TT, k:number) => void); // key number, data IObj
    }
    export function test4() {
    	var l_array:{[key:number]:IObj[]}; // declare variable
    	var l_each:IEach; // emulate interface instance fo call
    	l_each.each(l_array, function(v, k) { v.sort(function(v1, v2) { return v1.i -v2.i; }); }); // ERROR
    }
    
    • This topic was modified 6 years, 10 months ago by gorand.
    Attachments:
    You must be logged in to view attached files.
    #529973 Reply

    gorand
    Participant

    If you swap the function declaration and put the key first: number – then everything works correctly.

    
    interface IObj { i:number; }
    	
    interface IEach {
    	each<TT>(p_obj:{[key:number]:TT}, p_fn:(v:TT, k:number) => void); // key number to move first
    	each<TT>(p_obj:{[key:string]:TT}, p_fn:(v:TT, k:string) => void); // key string to move second
    }
    	
    export function test4() {
    	var l_array:{[key:number]:IObj[]};
    	var l_each:IEach; // emulate interface instance
    	l_each.each(l_array, function(v, k) { v.sort(function(v1, v2) { return v1.i -v2.i; }); });
    }
    

    Why is this happening? How to fix it?

    • This reply was modified 6 years, 10 months ago by gorand.
    Attachments:
    You must be logged in to view attached files.
    #530210 Reply

    support-swapna
    Moderator

    gorand,

    Sorry that you are seeing this issue. Thank you for the details and the screenshots. We are investigating the problem and we will get back to you soon.

    Apologies for inconvenience caused.

    –Swapna
    MyEclipse Support

    #530317 Reply

    support-swapna
    Moderator

    Gorand,

    The problem reported by you is a limitation in TypeScript. I am afraid we cannot fix it at our end.
    I suggest you cross post to TypeScript or development related forums like stackoverflow.com for better suggestions from the developer community.

    Sorry that we couldn’t assist further.

    –Swapna
    MyEclipse Support

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Error detecting incoming parameters when using generic type – how to fix it

You must be logged in to post in the forum log in