swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[typescript/angular2] compilation error in generated artifcats

Open jeusdi opened this issue 9 years ago • 5 comments

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

jeusdi avatar Dec 12 '16 18:12 jeusdi

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 avatar Dec 13 '16 06:12 todrules

@todrules is it correct to say that it was working fine before? or it never work for you?

wing328 avatar Dec 13 '16 06:12 wing328

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 avatar Dec 13 '16 07:12 todrules

@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

wing328 avatar Dec 13 '16 07:12 wing328

@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.

wing328 avatar Feb 15 '17 13:02 wing328