amplify-js: Application is not compiling due to the typing

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

# Put output below this line
angular: 17
typescript:5.3.3
@aws-amplify/ui-angular: 5.0.10
aws-amplify: 6.0.17

Describe the bug

Application is not compiling due to the typing

Expected behavior

Application to compile

Reproduction steps

after migration from v5 to v6

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line

Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:10 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:16 - error TS2339: Property 'error' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                   ~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:23 - error TS2339: Property 'url' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                          ~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signOut.ts:67:11 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

67   const { type } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/updateMFAPreference.ts:48:4 - error TS7030: Not all code paths return a value.

48 ): CognitoMFASettings | undefined {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:62:4 - error TS7030: Not all code paths return a value.

62    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:67:4 - error TS7030: Not all code paths return a value.

67    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:144:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.
  Type 'number' is not assignable to type 'string'.

144   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:207:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.

207   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:854:4 - error TS7030: Not all code paths return a value.

854 ): AuthSignInOutput | undefined {
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:978:44 - error TS7030: Not all code paths return a value.

978 export function getMFAType(type?: string): AuthMFAType | undefined {
                                               ~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/core/src/clients/middleware/retry/defaultRetryDecider.ts:19:34 - error TS2339: Property 'code' does not exist on type '(Error & MetadataBearer) | (Error & { code: string; })'.
  Property 'code' does not exist on type 'Error & MetadataBearer'.

19   const errorCode = parsedError?.code;
                                    ~~~~


Error: node_modules/@aws-amplify/core/src/clients/serde/json.ts:17:3 - error TS7030: Not all code paths return a value.

17   return;


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Okay, my bad, I was also importing stuff from from '@aws-amplify/core/src'; after changing to from '@aws-amplify/core/dist/esm'; it works well indeed

Can confirm this fixes all of the import errors. I was facing errors similar to https://github.com/aws-amplify/amplify-js/issues/13050#issuecomment-1964651588. Thanks atinary-ndefago

Okay, my bad, I was also importing stuff from from '@aws-amplify/core/src'; after changing to from '@aws-amplify/core/dist/esm'; it works well indeed

It was the same error, adding "strictNullChecks": true to my tsconfig solved it, thanks @ralphkurche!

Okay, my bad. I had a deeper look and found that I was accidentally importing a type from the src folder. By replacing import { HubCallback } from '@aws-amplify/core/src'; with import { HubCallback } from '@aws-amplify/core/dist/esm';the src package is no longer included in the build. I just realized this, after running tsc with the "explainFiles": true flag.

I also get a build error starting with release v6.0.17:

Error: node_modules/@aws-amplify/core/src/clients/middleware/retry/defaultRetryDecider.ts:19:34 - error TS2339: Property 'code' does not exist on type '(Error & MetadataBearer) | (Error & { code: string; })'.
  Property 'code' does not exist on type 'Error & MetadataBearer'.

19   const errorCode = parsedError?.code;

I work with a legacy project which doesn’t use the TS strict settings. If I set "strictNullChecks": true in my tsconfig.json the error in the defaultRetryDecider.ts seems to disappear, but unfortunately I cannot build my project in its current state with this setting.

Hello @cwomack, the type error persist after deleting the node_module folder and the lock file

In order for us to be able to help, can you please share some more details about the type errors you’re seeing?

If you have the error messages, logs, reproduction steps, code snippets, etc please share them as well.

Hello @cwomack, the type error persist after deleting the node_module folder and the lock file