[typescript/angular2] compilation error in generated artifcats
Description
Code generated:
/**
*
* Extends object by coping non-existing properties.
* @param objA object to be extended
* @param objB source object
*/
private extendObj<T1,T2>(objA: T1, objB: T2) {
for(let key in objB){
if(objB.hasOwnProperty(key)){
objA[key] = objB[key]; <<<<<<<<<<<<<<<<<
}
}
return <T1&T2>objA;
}
Error message:
file: 'file:///d%3A/projects/living/user-platform/cest/ts/api/users.service.ts'
severity: 'Error'
message: 'Type 'keyof T2' cannot be used to index type 'T1'.'
at: '65,17'
source: 'ts'
My package.json is:
{
"name": "cest",
"version": "0.1.0-unstable0009",
"description": "Living Community Endpoint REST Client",
"main": "./js/index.js",
"typings": "./js/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "tsc"
},
"keywords": [
"living",
"cest",
"commty"
],
"author": "Living Digital Way",
"license": "ISC",
"devDependencies": {
"@types/core-js": "^0.9.34",
"typescript": "^2.1.4"
},
"publishConfig": {
"registry": "http://nuget.living-digital-way.com:81/npm/npm_unstable"
},
"dependencies": {
"@angular/common": "^2.2.4",
"@angular/core": "^2.2.4",
"@angular/http": "^2.2.4",
"@angular/platform-browser": "^2.2.4",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.21"
}
}
And tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"baseUrl": "./ts",
"outDir": "js"
},
"exclude": [
"node_modules",
"js"
]
}
Swagger-codegen version
2.2.3-SNAPSHOT
I'm getting the exact same error.
Typescript: 2.1.4 Swagger CodeGen: 2.3.0 (built it a week ago) @angular: 2.3.0
I'm also using awesome-typescrpit-loader 3.0.0-beta.13. I've had a few problems with that loader lately so thought I'd mention it.
@todrules is it correct to say that it was working fine before? or it never work for you?
It was working on another project I was working on. And while troubleshooting just now, I rolled back Typescript from 2.1.4 to 2.1.1, and it's working. So, something is getting introduced in the newest version of TS that is causing this issue, but at least there's a workaround for now.
@todrules thanks for helping us to pinpoint the issue to Typescript version update. We'll need a fix to be compatible with the latest version as well as old version (e.g. 2.1.1) of TS.
cc @Vrolijkx
@todrules https://github.com/swagger-api/swagger-codegen/pull/4562 has been merged into master. Please pull the latest to give it a try. I believe it should address the issue that you reported if I'm not mistaken.