CodePlexProject Hosting for Open Source Software
An unexpected error has occured.
There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Voted
No files are attached
serjic_shkredov wrote Oct 8, 2012 at 8:26 PM
dflor003 wrote Nov 5, 2012 at 5:13 PM
seanhess wrote Nov 12, 2012 at 3:28 PM
jviereck wrote Dec 26, 2012 at 8:18 PM
function mapFunc(elm: _A[], foo: _A): _A { return elm[0]; } // ------------------------------------------------- // Tests! // Basic test var a:number[] = [1,2]; var b:number[] = null; var c:number = null;
jviereck wrote Dec 26, 2012 at 8:20 PM
function mapFunc(elm: _A[], foo: _A): _A { return elm[0]; } // Basic test var a:number[] = [1,2]; var c:number = null; c = mapFunc(a, 1);
dflor003 wrote Dec 27, 2012 at 1:50 PM
jviereck wrote Dec 28, 2012 at 8:34 AM
function mapFunc<TSomeType>(elm: TSomeType[], foo: TSomeType): TSomeType {
function map(arr: _A[], fn: (entry: _A, arr?: _A[], scope?: any) => _B, scope?: any): _B[] {
Also, not an absolute requirement, but in C# the compiler infers generic type parameters when it has enough information on how your method is being used. Given the level of type inference that TypeScript is using, it doesn't seem that far fetched that TypeScript generics would do the same type inference.
mapFunc
number
dflor003 wrote Jan 7 at 3:57 PM
for(var i = 0; i < arrayToSearch.length; i++) { var element: MyType1 = arrayToSearch[i]; var value: AnotherType = element[key]; if (value) return value; }
jonturner wrote Feb 27 at 3:59 PM
interface Array<T> { map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[]; }
interface Message { target:any; source:any; data:any; } interface MessageArray<T extend Message> { // T now has Message structure, without extends it's assumed to be {} }
Wolverine_ wrote Mar 1 at 6:02 PM
dflor003 wrote Mar 1 at 6:45 PM
clausreinke wrote Mar 1 at 9:47 PM
jonturner wrote Mar 12 at 9:49 PM
clausreinke wrote Mar 13 at 3:23 PM
I'm not clear on your point. Are you saying that it's powerful tool to say this: GenericType<A, A, A>? I'm not familiar with this usage pattern, generally I'm used to each type parameter being listed only once.
interface Gen<A,A> ...
Gen<X,Y>
X
Y
Can you give an example of a "type constructor parameter"?
Array<T>
Array
Array<String>
Set<T>
Map<IndexT,ValueT>
interface Select<Constructor,Index,Element> { select: Constructor<Index,Element> => Index => Element } var IntArraySelect : Select<Array,Int> = { select : ( arr, ind ) => arr[ ind ] };
Constructor
Select
map
A system of constructor classes: overloading and implicit higher-order polymorphism Mark P. Jones, In FPCA '93: Conference on Functional Programming Languages and Computer Architecture, Copenhagen, Denmark, June 1993. http://web.cecs.pdx.edu/~mpj/pubs/fpca93.html
EcmaScript/TypeScript | Haskell -------------------------------------------- object/class | value/type interface | type class interface implementation | type class instance generic | polymorphic
jonturner wrote Mar 20 at 4:27 PM
interface Gen<A> { myfunc(x:A, y:A): bool; } var myvar : Gen<{x: number}>; // substitution of Gen<{x: number}> specializes to: interface Gen<{x: number}> { myfunc(fst: {x: number}, snd: {x: number}): bool; } // now assignment compatibility kicks in and the following is valid: myvar.myfunc({x: 3}, {x: 4, y: 5});
interface Gen<A, B extends A> { ... }
LukeH wrote Mar 25 at 11:58 PM
vamp wrote Apr 1 at 2:57 PM
T map<T>(T value){ return Value; } map(new Date()).get| // getDate, getDay, getFullYear, ...
DRubino wrote May 7 at 3:03 AM
LukeH wrote May 7 at 4:10 PM
function map<T>(value: T) { return value; } map(new Date()).get| // getDate, getDay, getFullYear, ...
function cloneElement<T extends HTMLElement>(element: T): T { return <T>element.cloneNode(); }
Sign in to add a comment or to set email notifications
Keyboard shortcuts are available for this page.