Skip to content
New issue

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

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

Already on GitHub? # to your account

Issue with v7 & TypeScript 3.2 for array or object validation #64

Closed
cyrilletuzi opened this issue Dec 19, 2018 · 4 comments
Closed

Issue with v7 & TypeScript 3.2 for array or object validation #64

cyrilletuzi opened this issue Dec 19, 2018 · 4 comments

Comments

@cyrilletuzi
Copy link
Owner

cyrilletuzi commented Dec 19, 2018

In v7 of the lib, due to this regression in TypeScript 3.2, there is a problem with JSON schemas for objects or array validation if you use the generic JSONSchema interface:

const schema: JSONSchema = {
  type: 'object',
  properties: {
    firstName: { type: 'string' },
    lastName: { type: 'string' },
    age: { type: 'number' }
  },
  required: ['firstName', 'lastName']
};

or if you put a schema for an object or array directly in the method options:

this.localStorage.getItem<User>('user', { schema: {
  type: 'object',
  properties: {
    firstName: { type: 'string' },
    lastName: { type: 'string' },
    age: { type: 'number' }
  },
  required: ['firstName', 'lastName']
} });

Other schemas (string, numeric, boolean) are not affected.

Despite it's a regression, TypeScript team visibly doesn't plan to fix this until TypeScript 3.4 (yes, you've heard right...). So it has been decided to not support TypeScript 3.2.

If you're still on Angular 7.0 or 7.1 (so with TypeScript 3.1), there will be no problem with compilation. But as VS Code already uses TypeScript 3.2, errors can appear inside the editor.

If you upgraded to Angular 7.2, stick to TypeScript 3.1. Angular 7.2 still supports TS 3.1, and TS 3.2 adds nothing very interesting (except issues), so there is no need to rush the update. If you upgrade your Angular app via ng update, the CLI may update to TS 3.2, so revert this with this command:

npm install typescript@3.1 -D

TS 3.2 issue can be bypassed by casting each JSON schema and subschemas, but we do not recommend this option as it requires a lot of work, that may need to be reverted in v8 of this lib.

Version 8 of the lib will fix these TS problems once and for all (already ready in #74). But as it will imply some breaking changes, I have to wait for v8.

Another solution is to go back to v6 of the lib, which supports Angular 7 with TypeScript 3.1 and TypeScript 3.2:

npm install @ngx-pwa/local-storage@6

Sorry for this issue, but it's beyond my control and TS team doesn't care.

@cyrilletuzi cyrilletuzi self-assigned this Dec 19, 2018
@cyrilletuzi
Copy link
Owner Author

Waiting for microsoft/TypeScript#29168

@cyrilletuzi cyrilletuzi changed the title JSONSchema interfaces issues with TypeScript 3.2 JSONSchema generic interface issue with TypeScript 3.2 Jan 2, 2019
@cyrilletuzi cyrilletuzi pinned this issue Jan 2, 2019
@cyrilletuzi cyrilletuzi changed the title JSONSchema generic interface issue with TypeScript 3.2 JSONSchema generic interface issue with TypeScript 3.2 for array or object validation Jan 12, 2019
@cyrilletuzi cyrilletuzi changed the title JSONSchema generic interface issue with TypeScript 3.2 for array or object validation Issue with TypeScript 3.2 for array or object validation Jan 27, 2019
@cyrilletuzi cyrilletuzi added this to the v8.0 milestone Jan 27, 2019
@cyrilletuzi
Copy link
Owner Author

Fixed in #74, which will be released in v8.

Keeping the issue open for v7 documentation.

@cyrilletuzi
Copy link
Owner Author

v8 beta is available for testing, see #76

@cyrilletuzi cyrilletuzi changed the title Issue with TypeScript 3.2 for array or object validation Issue with v7 & TypeScript 3.2 for array or object validation Feb 11, 2019
@cyrilletuzi
Copy link
Owner Author

This is fixed in v8.

@cyrilletuzi cyrilletuzi unpinned this issue Jun 4, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant