I'm having issues compiling the following. it's included in an old project with the comment - "This is a TS1.8 feature. Leave it in to ensure the environment is running the right ts".
function assign<T extends U, U>(target: T, source: U): T {
for (let id in source) {
target[id] = source[id]; // error TS2322: Type 'U[Extract<keyof U, string>]' is not assignable to type 'T[Extract<keyof U, string>]'.
}
return target;
}
I'm compiling it with the following command
tsc -p tsconfig.json
And this tsconfig.json
{
"include": [
"Scripts/TypeScripts/**/*"
],
"compilerOptions": {
"target": "es5",
"module": "amd",
"sourceMap": false,
"watch": false
}
}
tsc -v yields Version 3.4.5.
When I try it in the playground, I also see the error, which makes me think that it is indeed invalid code. However, this poses the questions what was I thinking when I wrote that comment and how come it's been compiling for 2 years (or has it??)
So - my question: Is this valid TS Code? If not, was it ever?
Thanks :-)