Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
Calling Auth.signUp from an Angular Package Format Library produces type error?

Most of the aws-amplify auth functions can be call from Angular libraries. For example Auth.signout() works fine.

However I tried to put the following implementation in a library service:

  /**
   * @param firstName The first name
   * @param lastName The last name
   * @param email The email
   * @param password The password
   * @returns The signup result
   */
   export function signUp(
    firstName: string,
    lastName: string,
    email: string,
    password: string) {
    return Auth.signUp({
      username: email,
      password,
      attributes: {
        email,
        name: firstName,
        given_name: firstName,
        family_name: lastName
      }
    });
  }

However when any of the functions in the library are imported like this for example:

import { Component } from '@angular/core';
import { getCurrentAuthenticatedUserAttributes} from 'amplifylibe'
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 't1';
}

It produces the following error:


Build at: 2022-02-04T20:58:53.577Z - Hash: bd84be34957baf56 - Time: 112ms

Error: node_modules/amplifylibe/lib/auth.functions.d.ts:1:23 - error TS2688: Cannot find type definition file for 'amazon-cognito-identity-js'.

1 /// <reference types="amazon-cognito-identity-js" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/amplifylibe/lib/auth.functions.d.ts:14:118 - error TS2307: Cannot find module 'amazon-cognito-identity-js' or its corresponding type declarations.

14 export declare function signUp(firstName: string, lastName: string, email: string, password: string): Promise<import("amazon-cognito-identity-js").ISignUpResult>;
                                                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To show this I published a minimal library with the functions to NPM:

https://www.npmjs.com/package/amplifylibe

The corresponding github repository is: https://github.com/fireflysemantics/tsamplifyapidemotest

That contains the signup function. I also created an Angular 13 app that produces the error when ng serve is run:

git clone git@github.com:fireflysemantics/tsamplifylibdemoapp.git
cd tsamplifylibdemoapp
npm i 
ng serve

Any ideas on how to go about fixing this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So it looks like the fix is pretty simple. Just declare a Promise<any> return type like this:

  /**
   * @returns The result promise
   */
  async getCurrentAuthenticatedUserAttributes(): Promise<any> {
    const { attributes } = await Auth.currentAuthenticatedUser();
    return attributes
  }

Without the return type declared, it looks like Typescript tries to infer the correct return type from amplify and this is unavailable to the library when the application compiles.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda