Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
¿Llamar a Auth.signUp desde una biblioteca de formato de paquete angular produce un error de tipo?

La mayoría de las funciones de autenticación de aws-amplify se pueden llamar desde las bibliotecas de Angular. Por ejemplo Auth.signout() funciona bien.

Sin embargo, traté de poner la siguiente implementación en un servicio de biblioteca:

 /** * @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 } }); }

Sin embargo, cuando cualquiera de las funciones en la biblioteca se importa así, por ejemplo:

 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'; }

Produce el siguiente 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>; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Para mostrar esto, publiqué una biblioteca mínima con las funciones de NPM:

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

El repositorio de github correspondiente es: https://github.com/fireflysemantics/tsamplifyapidemotest

Que contiene la función de signup . También creé una aplicación Angular 13 que produce el error cuando se ejecuta ng serve :

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

¿Alguna idea sobre cómo arreglar esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Así que parece que la solución es bastante simple. Simplemente declare un tipo de retorno Promise<any> como este:

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

Sin el tipo de retorno declarado, parece que Typescript intenta inferir el tipo de retorno correcto de amplificar y esto no está disponible para la biblioteca cuando se compila la aplicación.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!