asked    Eunice     2018-10-22       javascript       24 view        3 Answers

[SOLVED] Argument of type 'any[]' is not assignable to parameter of type 'A'. Property 'a' is missing in type 'any[]'

I'm a very beginner in TypeScript and now I'm trying to understand how interfaces works in a Class Method of React Component. I created a simple case for it, but it does not work. I always gets an error like in this post title.

I'll be pleased for any help.

import React, { Component } from 'react'

interface A {
  a: any[]
}

class Test extends Component {
  _getName = (a: A) => {
    return a
  }
  render() {
    const a = []
    return (
      <div>{this._getName(a)}</div>
    )
  }
}

export default Test

  3 Answers  

        answered    Corey     2018-10-22      

this._getName(a) expects a to be of type A. A is defined as an object with a property a that is of type any[]. Your call-time a inside render is of type [].

I'm not sure what it is you are trying to accomplish with this code but I guess what you want is to say that the parameter a in _getName should be of type any[]? Then you probably need type A = any[].



        answered    Burton     2018-10-22      

interface A {
  a: any[]
}

means that the object that implements the interface "A" is required to have a property called "a" that will be of type "any[]" (array of any type)

but here:

const a = []

it looks like a is just an empty array - not an object, thus not having properties

In my opinion you don't need an interface here. Try instead:

  _getName = (a: any[]) => {
    return a
  }


        answered    Colbert     2018-10-22      

It is necessary to do so:

class Test extends Component {
  _getName = (a: A) => {
    return a.a;
  }
  render() {
    const a = {a: []};
    return this._getName(a);
  }
}




Your Answer





 2018-10-22         Ronald

Add all duplicate values in mysqli

I have an tabel trade as following:- bm | m | price | amount | status USD|BTC| 0.01 | 1 | active USD|BTC| 0.01 | 2.5 | active USD|BTC| 0.4 | 0.5 | active USD|BTC| 0.4 | 0.22 | activeI want to add amounts of duplicate price i.e 0.01 and 0.4 where status is active and show them so that the result is like:- price | amount 0.01 | 3.5 0.4 | 0.722I have tried an php query for showing but it shows values and rows as it is. Help please. Simply do a GROUP BY, use SUM() to calculate the sum for each price!select price, sum(amount)from tablenameWHERE bm = 'usd...
 php                     1 answers                     105 view
 2018-10-22         Hermosa

Integrate Single Page application into WordPress

I have lots of basic single page applications which have html, css, js files I would like to publish them on wordpress. I can add them like external website but when I used this, I have to add all static parts (header, menu, footer etc) to the app.html file. And I have to do this for each application. This is not sustainable and good solution for sure. This is why I am looking for some way to add this page after menu in wp like other pages. I would like to give you folder hierarchy to concrete the problem. || - apps || - || - app1 || - || - || - app1.html || - || ...
 javascript                     2 answers                     106 view
 2018-10-22         Richard

How to create language select in twig template

I'm currently using symfony 3.2. and now i have a link like this :http://link.com?lang=en and in config/parameters I have allowed_locales -en, -ruHow could i create a language switcher in twig template like this : <a href="#" class="locales">EN<img src="{{ asset('assets/images/arrow-down.svg') }}" alt="arrow" class="arrow-down" /></a> <div class="locales-content" style="left:0;"> <a href="#">Russian</a> <a href="#">English</a>...
 php                     1 answers                     109 view