Angular /打字稿中的GraphQL和错误TS2345

时间:2019-03-21 18:33:47

标签: typescript graphql

在有角度的应用程序中使用graphql端点,并且在编译时一直出现此错误。它似乎并没有破坏应用程序,只是破坏了应用程序的最终生产版本。

我的查询设置如下:

initializeQuery(trx: string, conf: any) {
    console.log(`TransactionID: ${trx} of type: ${typeof trx}`);
    console.log(`Confidence: ${conf} of type: ${typeof conf}`);
    this.trxQuery = this.apollo.watchQuery<Query>({
      query: gql`
      query getTransactions($transID: String!, $confidence: Float) {
        transactions(parentID: $transID, confidence: $confidence) {
          id
          childrens {
            id
            name
            email
            phone
            age
            connectionInfo {
              type
              confidence
            }
          }
          name
          email
          phone
          age
        }
      }
      `,
      variables: {
        transID: trx,
        confidence: (typeof conf === 'string') ? parseFloat(conf): conf,
      }
    }).valueChanges.subscribe((query: Query) => {
      console.log(query);
      let {transactions} = query.data as Transaction;
      this.rowData = transactions.childrens.map(c => ({
        id: c.id,
        connectionInfo: c.connectionInfo.type,
        confidence: c.connectionInfo.confidence,
        name: c.name,
        email: c.email,
        phone: c.phone,
        age: c.age,
      }));
    });
  }

该错误表明我的类型不匹配。我不知道如何将其设置为我没有收到此错误的地方。

  

错误TS2345:类型'(query:Query <{},R>)=> void'的参数无法分配给参数   类型为((value:ApolloQueryResult>)=> void'。

0 个答案:

没有答案