get method type to boolean is resolved to unknown #302
-
Hello, Since the migration from Angular 8 to 9, When using a generic type as boolean, the overload should be: get<T = boolean>(key: string, schema: JSONSchemaBoolean): Observable<boolean | undefined>; But in reality, the result is: get<T = unknown>(key: string, schema?: JSONSchema): Observable<unknown>; You can checkout the problem on StackBlitz on the app.component.ts. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello, thanks for the precise issue and the stackblitz reproduction. This is working as intended. You're getting a value from client-side storage. So assuming you'll get what you previously stored is not safe: it could have been forged. So it's why the lib is returning So what you need to do is this: this.storage.get('hello', { type: 'boolean' }); But this is not a change in v9 of this lib. It was a change in v7. So maybe something during Angular v8 to v9 migration made you aware of this, but this is not new. More information about: |
Beta Was this translation helpful? Give feedback.
-
Thank you for the information. And yes, Angular 9 uses now a more recent version of TypeScript. |
Beta Was this translation helpful? Give feedback.
Hello, thanks for the precise issue and the stackblitz reproduction.
This is working as intended.
You're getting a value from client-side storage. So assuming you'll get what you previously stored is not safe: it could have been forged. So it's why the lib is returning
unknown
if you don't provide a JSON schema for runtime validation (validation can't be done at compilation time via a cast). You can see in the overload you provided that the second param is required.So what you need to do is this:
But this is not a change in v9 of this lib. It was a change in v7. So maybe something during Angular v8 to v9 migration made you aware of this, bu…