reactjs - Multiple errors on typescript -
i created following class in asp.net core react application:
import * react 'react'; interface myinputprops { inputtype: string; id: string; classname: string; parentfunction: (string) => void; } export class logininput extends react.component<myinputprops, {}> { constructor() { super(); this.onchange = this.onchange.bind(this); } private onchange(e) { this.props.parentfunction(e.target.value); } public render() { return <input type={this.props.inputtype} id={this.props.id} classname={this.props.classname} placeholder="username" onchange={this.onchange} />; } }
now i'm getting following errors:
- (ts) parameter 'string' implicitly has 'any' type.
- (ts) parameter 'e' implicitly has 'any' type.
can point me doing wrong here?
edit
in solution have following class works fine:
import * react 'react'; import axios 'axios'; import country './country'; import countrymodel './models/countrymodel'; const countriesuri = 'https://restcountries.eu/rest/v2/all?fields=name;alpha2code'; interface props { onchange: (string) => void; } interface state { countries: countrymodel[]; } class countrylist extends react.component<props, state> { constructor() { super(); this.state = { countries: [] }; this.onchange = this.onchange.bind(this); } componentwillmount() { this.getcountries(); } private getcountries() { // } private onchange(e) { this.props.onchange(e.target.value); } public render() { return <select onchange={this.onchange} ref='countries'> { // } </select>; } } export default countrylist;
you have define types of variables e.g.
interface myinputprops { parentfunction: (string:string) => void; } private onchange(e:any) { this.props.parentfunction(e.target.value); }
the error message means if not define type implicitly add :any
it. reason check compiler option noimplicitany: true
in tsconfig.json
Comments
Post a Comment