amplify-js: TypeScript type errors from `amazon-cognito-identity-js`

New Problem:

node_modules/amazon-cognito-identity-js/index.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: UpdateAttributesNodeCallback, ClientMetadata, AuthenticationDetails, ChallengeName, CognitoUser, CognitoUserAttribute, CognitoUserPool, CognitoUserSession, CognitoAccessToken, CognitoIdToken, CognitoRefreshToken, CookieStorage, UserAgent, appendToCognitoUserAgent, WordArray

1 declare module 'amazon-cognito-identity-js' {
  ~~~~~~~

  node_modules/@aws-amplify/auth/node_modules/amazon-cognito-identity-js/index.d.ts:1:1
    1 declare module 'amazon-cognito-identity-js' {
      ~~~~~~~
    Conflicts are in this file.

node_modules/amazon-cognito-identity-js/index.d.ts:4:14 - error TS2649: Cannot augment module 'NodeCallback' with value exports because it resolves to a non-module entity.

4  export type NodeCallback<E, T> = (err?: E, result?: T) => void;
               ~~~~~~~~~~~~

node_modules/amazon-cognito-identity-js/index.d.ts:402:3 - error TS2687: All declarations of 'domain' must have identical modifiers.

402   domain: string;
      ~~~~~~

node_modules/amazon-cognito-identity-js/index.d.ts:402:3 - error TS2717: Subsequent property declarations must have the same type.  Property 'domain' must be of type 'string | undefined', but here has type 'string'.

402   domain: string;
      ~~~~~~

  node_modules/@aws-amplify/auth/node_modules/amazon-cognito-identity-js/index.d.ts:402:3
    402   domain?: string;
          ~~~~~~
    'domain' was also declared here.

Original Issue

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Other

Please describe your bug.

When running TS build on the project, I am getting lots of errors:

tsc --noEmit
node_modules/@aws-amplify/ui-react/dist/index.d.ts:29:9 - error TS2502: 'FormFields' is referenced directly or indirectly in its own type annotation.

29     var FormFields: typeof FormFields;
           ~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:224:9 - error TS2502: 'SignIn' is referenced directly or indirectly in its own type annotation.

224     var SignIn: typeof SignIn;
            ~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:225:9 - error TS2502: 'SignUp' is referenced directly or indirectly in its own type annotation.

225     var SignUp: typeof SignUp;
            ~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5775:48 - error TS2693: 'DataStoreItemProps' only refers to a type, but is being used as a value here.

5775 declare const index_DataStoreItemProps: typeof DataStoreItemProps;
                                                    ~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5776:54 - error TS2693: 'DataStoreCollectionProps' only refers to a type, but is being used as a value here.

5776 declare const index_DataStoreCollectionProps: typeof DataStoreCollectionProps;
                                                          ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5777:49 - error TS2693: 'DataStoreItemResult' only refers to a type, but is being used as a value here.

5777 declare const index_DataStoreItemResult: typeof DataStoreItemResult;
                                                     ~~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5778:55 - error TS2693: 'DataStoreCollectionResult' only refers to a type, but is being used as a value here.

5778 declare const index_DataStoreCollectionResult: typeof DataStoreCollectionResult;
                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5779:51 - error TS2693: 'DataStoreBindingProps' only refers to a type, but is being used as a value here.

5779 declare const index_DataStoreBindingProps: typeof DataStoreBindingProps;
                                                       ~~~~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5780:54 - error TS2693: 'DataStorePredicateObject' only refers to a type, but is being used as a value here.

5780 declare const index_DataStorePredicateObject: typeof DataStorePredicateObject;
                                                          ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5872:48 - error TS2344: Type '_0' does not satisfy the constraint 'boolean'.

5872 type index_TextFieldProps<_0> = TextFieldProps<_0>;
                                                    ~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5876:50 - error TS2344: Type '_0' does not satisfy the constraint 'ElementType'.
  Type '_0' is not assignable to type 'FC<any>'.

5876 type index_HTMLElementType<_0> = HTMLElementType<_0>;
                                                      ~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5877:44 - error TS2344: Type '_0' does not satisfy the constraint 'ElementType'.
  Type '_0' is not assignable to type 'FC<any>'.

5877 type index_ElementProps<_0> = ElementProps<_0>;
                                                ~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5878:56 - error TS2344: Type '_1' does not satisfy the constraint 'ElementType'.
  Type '_1' is not assignable to type 'FC<any>'.

5878 type index_PrimitiveProps<_0, _1> = PrimitiveProps<_0, _1>;
                                                            ~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5879:70 - error TS2344: Type '_1' does not satisfy the constraint 'ElementType'.
  Type '_1' is not assignable to type 'FC<any>'.

5879 type index_PrimitivePropsWithRef<_0, _1> = PrimitivePropsWithRef<_0, _1>;
                                                                          ~~

node_modules/@aws-amplify/ui-react/dist/index.d.ts:5880:46 - error TS2344: Type '_1' does not satisfy the constraint 'ElementType'.
  Type '_1' is not assignable to type 'FC<any>'.

5880 type index_Primitive<_0, _1> = Primitive<_0, _1>;

What’s the expected behaviour?

No errors.

Help us reproduce the bug!

Use strict TS. Use your package.

Code Snippet

N/A

Additional information and screenshots

Related issue: https://github.com/aws-amplify/amplify-js/issues/7188

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@moltar Feel free to reopen if adding "skipLibCheck": true doesn’t fix the errors.

Just to provide an update on this. Some code in ui-react has moved to ui-react-core, and during the process we enabled TS strict mode. In addition the react-native package has TS strict mode enabled, and we will ensure any new packages are strict. We are planning to completely enable strict mode on the main react package as well early next year.

Hi @moltar,

We will be looking into enabling strict: true on the ui-react package in this issue: https://github.com/aws-amplify/amplify-ui/issues/1109

In the meantime, please give the option @ErikCH mentioned a try. This is actually the default setting in Create React App projects and will only disable strict type checking for libraries not your own code (which I realize still isn’t ideal). You can try out my TS CRA example here and see that it compiles without any errors with the “skipLibCheck” option enabled while leaving “strict” on for the rest of the project.