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
fix(auth): Missing type in configure function #10045
fix(auth): Missing type in configure function #10045
Conversation
6de5928
to
e0ae056
Compare
e0ae056
to
78328c7
Compare
78328c7
to
fced710
Compare
Hi guys, can we have one more approver here? It's a simple change, won't take long to review. |
@micksatana, Thanks for your contribution and also updating the docs at the same time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
@micksatana ● Test suite failed to run
@aws-amplify/auth: TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
@aws-amplify/auth: __tests__/auth-configure-test.ts:16:19 - error TS2345: Argument of type '{ userPoolId: string; userPoolWebClientId: string; region: string; identityPoolId: string; mandatorySignIn: boolean; storage: {}; }' is not assignable to parameter of type 'AuthOptions'.
@aws-amplify/auth: Types of property 'storage' are incompatible.
@aws-amplify/auth: Type '{}' is missing the following properties from type 'ICognitoStorage': setItem, getItem, removeItem, clear
@aws-amplify/auth: 16 auth.configure(opts); |
@@ -139,7 +139,7 @@ export class AuthClass { | |||
return 'Auth'; | |||
} | |||
|
|||
configure(config?) { | |||
configure(config?: AuthOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change unfortunately. Auth.configure
can also use the content of aws-exports.js
file. Maybe we could do something to overload this function? @jamesaucode what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type '{}' is missing the following properties from type 'ICognitoStorage'
because the test case use {}
instead of just left it out when storage not exists. The test mentioning throw error when storage is empty
, so it should throw and it does. When I ran test locally, it got
@aws-amplify/auth: PASS __tests__/auth-configure-test.ts
@aws-amplify/auth: ● Console
@aws-amplify/auth: console.error ../core/lib/Logger/ConsoleLogger.js:129
@aws-amplify/auth: [ERROR] 40:02.742 AuthClass - The storage in the Auth config is not valid!
And
@aws-amplify/auth: Test Suites: 11 passed, 11 total
@aws-amplify/auth: Tests: 200 passed, 200 total
@aws-amplify/auth: Snapshots: 1 passed, 1 total
@aws-amplify/auth: Time: 14.282s
I'm not sure how the same test behave differently in CI though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test case want to test the fail case when it's an empty object. But it conflicts with type testing as the ICognitoStorage
type has all required properties. So to pass this test, either fix the test case to remove storage: {}
out, or make all ICognitoStorage
props optional. If the test case intent to test logic not type, I think we shouldn't test with empty object (without ts-ignore). It should test with undefined
instead. Or keep the empty object storage
but use ts-ignore
above the auth.configure(opts);
line because we intentionally make the type failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @micksatana - Just wanted to give you a heads up we are planning on pushing a bunch of changes to our Authentication category, and are planning on include changes in your PR as a part of that. Just wanted to reach out to make sure you know we did not abandon your contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdallahshaban557 acknowledged with thanks.
5b68474
to
66bfe31
Compare
Hi @micksatana - thank you for this contribution! We are currently working on improving our TS types, including adding support for typing the configure function. You can check out our RFC proposal here |
Description of changes
Missing type when using `Auth.configure`
Description of how you validated changes
In VSCode
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.