Skip to content

[TS][Angular2] Updated npm configuration to use new typescript2 typings system #5966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 8, 2017

Conversation

wing328
Copy link
Contributor

@wing328 wing328 commented Jul 2, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

Resolved merge conflicts for #5965

Sebastian List and others added 2 commits June 29, 2017 23:00
@wing328
Copy link
Contributor Author

wing328 commented Jul 2, 2017

I got the following errors when running npm install (which runs npm run build in post-install)

node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'.
      Type 'Observable<T>' is not assignable to type 'Observable<R>'.
        Type 'T' is not assignable to type 'R'.
node_modules/typescript/lib/lib.es2015.collection.d.ts(45,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/typescript/lib/lib.es2015.core.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'.
node_modules/typescript/lib/lib.es2015.iterable.d.ts(157,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts(133,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
typings/globals/core-js/index.d.ts(3,14): error TS2300: Duplicate identifier 'PropertyKey'.
typings/globals/core-js/index.d.ts(67,5): error TS2687: All declarations of 'name' must have identical modifiers.
typings/globals/core-js/index.d.ts(127,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.
typings/globals/core-js/index.d.ts(244,5): error TS2687: All declarations of 'flags' must have identical modifiers.
typings/globals/core-js/index.d.ts(258,5): error TS2687: All declarations of 'EPSILON' must have identical modifiers.
typings/globals/core-js/index.d.ts(293,5): error TS2687: All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.
typings/globals/core-js/index.d.ts(300,5): error TS2687: All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.
typings/globals/core-js/index.d.ts(439,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.
typings/globals/core-js/index.d.ts(439,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(446,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(474,5): error TS2687: All declarations of 'hasInstance' must have identical modifiers.
typings/globals/core-js/index.d.ts(480,5): error TS2687: All declarations of 'isConcatSpreadable' must have identical modifiers.
typings/globals/core-js/index.d.ts(486,5): error TS2687: All declarations of 'iterator' must have identical modifiers.
typings/globals/core-js/index.d.ts(492,5): error TS2687: All declarations of 'match' must have identical modifiers.
typings/globals/core-js/index.d.ts(498,5): error TS2687: All declarations of 'replace' must have identical modifiers.
typings/globals/core-js/index.d.ts(504,5): error TS2687: All declarations of 'search' must have identical modifiers.
typings/globals/core-js/index.d.ts(510,5): error TS2687: All declarations of 'species' must have identical modifiers.
typings/globals/core-js/index.d.ts(516,5): error TS2687: All declarations of 'split' must have identical modifiers.
typings/globals/core-js/index.d.ts(522,5): error TS2687: All declarations of 'toPrimitive' must have identical modifiers.
typings/globals/core-js/index.d.ts(528,5): error TS2687: All declarations of 'toStringTag' must have identical modifiers.
typings/globals/core-js/index.d.ts(534,5): error TS2687: All declarations of 'unscopables' must have identical modifiers.
typings/globals/core-js/index.d.ts(591,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.
typings/globals/core-js/index.d.ts(591,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(595,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.
typings/globals/core-js/index.d.ts(595,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(610,5): error TS2687: All declarations of 'size' must have identical modifiers.
typings/globals/core-js/index.d.ts(616,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(627,5): error TS2687: All declarations of 'size' must have identical modifiers.
typings/globals/core-js/index.d.ts(633,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(638,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
typings/globals/core-js/index.d.ts(646,27): error TS2344: Type 'K' does not satisfy the constraint 'object'.
typings/globals/core-js/index.d.ts(647,53): error TS2344: Type 'K' does not satisfy the constraint 'object'.
typings/globals/core-js/index.d.ts(648,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'prototype' must be of type 'WeakMap<object, any>', but here has type 'WeakMap<any, any>'.
typings/globals/core-js/index.d.ts(648,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(662,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'prototype' must be of type 'WeakSet<object>', but here has type 'WeakSet<any>'.
typings/globals/core-js/index.d.ts(662,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(674,5): error TS2687: All declarations of 'value' must have identical modifiers.
typings/globals/core-js/index.d.ts(786,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
variables.ts(1,10): error TS2305: Module '"/private/tmp/swagger-codegen/samples/client/petstore/typescript-angular2/npm/node_modules/@angular/core/index"' has no exported member 'InjectionToken'.

In master and 2.3.0, I also got errors running npm run build but the error messages are not the same. (I'm using Node v8.1.3)

We'll need to setup CI (travis) to cover TS Angular2 Petstore moving forward.

cc @Vrolijkx @taxpon @sebastianhaas @kenisteward

@kenisteward
Copy link
Contributor

kenisteward commented Jul 2, 2017 via email

@wing328
Copy link
Contributor Author

wing328 commented Jul 3, 2017

@kenisteward thanks for looking into it.

The last error definitely suggests that angular ( V4 or higher) is not
being installed as injection token only exists in 4 or higher .

I think we need to roll back that change to make the output work with Angular V2 and later add support for V4 or higher via the --ngVersion option.

@kenisteward
Copy link
Contributor

kenisteward commented Jul 3, 2017 via email

@sebastianhaas
Copy link
Contributor

sebastianhaas commented Jul 3, 2017

I think we need to roll back that change to make the output work with Angular V2 and later add support for V4 or higher via the --ngVersion option.

I agree it probably wasn't the best choice to implement InjectionToken without pinning Angular to >= 4.x.x to make sure it's available. But since people might be relying on it already, I'd rather recommend to upgrade the Angular version to 4.x.x in the package.json since it's just the latest version of Angular.

If someone decides to use an outdated Angular version, they have to use the injection token flag to get an API client with the old OpaqueToken and since this requires users to take action anyway, they would then have to additionally edit their package.json manually for now, until we get the version flag. This way, we would provide a working API client using the latest features of the latest Angular version out of the box.

@wing328
Copy link
Contributor Author

wing328 commented Jul 3, 2017

As a starting point, I'll add the ngVersion option to this branch so that we can add the support for both Angular 2.x and 4.x.

@wing328
Copy link
Contributor Author

wing328 commented Jul 3, 2017

Added ngVersion option. If I understand it correctly, we can use ngVersion to replace the useOpaqueToken option, right?

Feel free to submit PRs to this branch for enhancements/bug fixes and I'll merge accordingly.

@kenisteward
Copy link
Contributor

@wing328 this is correct. We can simply make sure that ngVersion 2 correctly complies with all that versions best practices and ngVersion 4 complies with all the newest ones. This being a change between the two.

@wing328
Copy link
Contributor Author

wing328 commented Jul 5, 2017

UPDATE: just pushed a commit to update rxjs version and now the TS Angular 4 client does not throw any error for npm run build:

npm|wing328-ts_angular2_typings⚡ ⇒ npm run build

> @swagger/angular2-typescript-petstore@0.0.1 build /private/tmp/swagger-codegen/samples/client/petstore/typescript-angular4/npm
> tsc --outDir dist/

npm|wing328-ts_angular2_typings⚡ ⇒ pwd     
/tmp/swagger-codegen/samples/client/petstore/typescript-angular4/npm
npm|wing328-ts_angular2_typings ⇒ 

@wing328
Copy link
Contributor Author

wing328 commented Jul 7, 2017

UPDATE: TS Angular2.x, 4.x do not report any error when running npm run build

If no further feedback, I'll merge this PR over the coming weekend.

@kenisteward
Copy link
Contributor

kenisteward commented Jul 7, 2017

@wing328 angular and rx are peer dependencies right? I haven't had a chance to look back at the generated package.json

@kenisteward
Copy link
Contributor

@wing328 Thanks!

@wing328
Copy link
Contributor Author

wing328 commented Jul 7, 2017

Note: Angular 4 is now the default

https://github.com/swagger-api/swagger-codegen/pull/5966/files#diff-3be636801e21582ce84672072bd183f5R38

@wing328 wing328 merged commit ed11da2 into 2.3.0 Jul 8, 2017
@wing328 wing328 deleted the wing328-ts_angular2_typings branch July 8, 2017 11:18
@wing328 wing328 mentioned this pull request Jul 27, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants