Skip to content
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

A TS fix for PPR #86

Merged
merged 2 commits into from
Nov 27, 2019
Merged

A TS fix for PPR #86

merged 2 commits into from
Nov 27, 2019

Conversation

bryan-gilbert
Copy link
Contributor

PPR uses strict typescript checking. This fix is required for PPR to use these common components.
Plus, fix large number of unit test failures
Updating the test package resolves numerous unit test errors that have the form
console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
TypeError: Cannot read property '_transitionClasses' of undefined

PPR uses strict typescript checking. This fix is required for PPR to use these common components.
Plus, fix large number of unit test failures
Updating the test package resolves numerous unit test errors that have the form
    console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
      TypeError: Cannot read property '_transitionClasses' of undefined
@saravankumarpa
Copy link
Contributor

@severinbeauvais plz review

@@ -63,7 +63,8 @@ export default class SbcHeader extends Vue {

get showLogin () : boolean {
let featureHide: any
const authApiConfig = JSON.parse(sessionStorage.getItem('AUTH_API_CONFIG'))
let config: string = sessionStorage.getItem('AUTH_API_CONFIG') || '{}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly typing config is not necessary here. getItem returns a string, so the type is implied. authApiConfig in the next line with still have type any.

As a side note, if I do enable strict and transpile the common-components, I get many more errors that just the one addressed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually getItem can also return null when the key does not exist. TS was not happy passing a possible null into the JSON.parse which requires a string.
https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not disputing that getItem returns string | null as a type. You already handle that with the || '{}' part so config is always going to be of type string. What I'm saying is you shouldn't explicitly declare types when it's not necessary. i.e let TypeScript do that for you as it will be less likely to make a mistake.

Ideally, it should be const config = sessionStorage.getItem('AUTH_API_CONFIG) || '{}'

I was incorrect by pointing out that authApiConfig would be any, as technically this will transpile in strict mode. If you wanted to be truly type-safe (which I assume is what you're going for by pushing for strict mode), you may want to read up on type safe JSON parsing: https://www.sparkbit.pl/type-safe-json-parsing/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please review update. thanks

@sutherlanda sutherlanda self-requested a review November 27, 2019 01:48
Copy link
Contributor

@sutherlanda sutherlanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above

Copy link
Contributor

@sutherlanda sutherlanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use const instead of let in this instance, but in the interests of getting you unblocked, let's just get this in.

@sutherlanda sutherlanda merged commit a2b3d28 into bcgov:master Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants