找不到名称 'attributes'。放大认证

Cannot find name 'attributes'. Amplify Auth

我已经使用 amplify add auth 向我的 angular 应用程序添加了授权。 之后我添加了

"requiredAttributes": [
    "email",
    "custom:firstName",
    "custom:lastName"
],

到amplify/backend/auth/XXX/parameters.json

  Schema:

    -
      Name: email
      Required: true
      Mutable: true

    -
      AttributeDataType: "String"
      Mutable: true
      Name: firstName
      StringAttributeConstraints:
        MaxLength: 256
        MinLength: 1

    -
      AttributeDataType: "String"
      Mutable: true
      Name: lastName
      StringAttributeConstraints:
        MaxLength: 256
        MinLength: 1

到amplify/backend/auth/XXX/XXX-cloudformation-template.yml

之后amplify push

我可以在控制台中看到这些自定义字段:

但是当我尝试像这样发送自定义字段时:

  import { Auth } from 'aws-amplify';

  ...

  signUp(email, password, firstName, lastName): Observable<any> {
    return fromPromise(Auth.signUp(
      email,
      password,
      attributes: {
        "custom:firstName": firstName,
        "custom:lastName": lastName
      }
    ));
  }

TypeScript 编译器抛出此错误:

Cannot find name 'attributes'.ts

应该是:

signUp(params: string | SignUpParams, ...restOfAttrs: string[]): Promise<ISignUpResult>

这是我的解决方法:

  signUp(username, password, firstName, lastName): Observable<any> {
    const signUpParams: any = {
      username,
      password,
      attributes: {
        'custom:firstName': firstName,
        'custom:lastName': lastName
      }
    };
    return fromPromise(Auth.signUp(
      signUpParams
    ));
  }