4 ms·
C++ style templates...? What's wrong with ripping TypeScript's generic implementation? It's simple, clean and direct function firstOf<T>(anArray: T[]): T {
by apatheticonion 8y ago
C++ style templates...?
What's wrong with ripping TypeScript's generic implementation?
It's simple, clean and direct
function firstOf<T>(anArray: T[]): T {
return anArray[0]
}
interface thing<T, Y> {
key: T
anotherOne: Y
}
const things: thing<string, string> = [
{ key: 'hello', anotherOne: 'world'},
{ key: 'value', anotherOne: 'thing'}
]
const result = firstOf<thing>(things)
- htfy96 8y agoTypescript, as I know, uses type erasure to implement generics, which can cause significant overhead in cases like JSON decoder.