i made a Class like this : It is very simple. i have a constructeur, with one value : ID which is must be pass has an argument, and the other are optionnal.
export default class Player {
// 1. Typage des propiétés d'un participant à GF.
id: number;
name: string;
picture: string;
status: number;
achievement: Array<number>;
biography: string;
pictures: Array<number>;
created?: Date;
// 2. Définition des valeurs par défaut des propriétés d'un Player.
constructor(
id: number,
name: string = 'name',
picture: string = 'http://...',
status: number = 0,
achievement:[0],
biography:string = "",
pictures:[0],
created: Date = new Date()
) {
// 3. Initialisation des propiétés d'un Player.
this.id = id;
this.name = name;
this.picture = picture;
this.status = status;
this.achievement = achievement;
this.biography = biography;
this.pictures = pictures;
this.created = created;
}
}
And i want to make a new component REACT like this :
import React, {FunctionComponent, useState} from 'react';
import PlayerForm from '../components/player/player-form';
import Player from '../models/player.class';
const PlayerAdd: FunctionComponent = () => {
const [id] = useState<number>(new Date().getTime());
const [player] = useState<Player>( new Player(id) );
return (
<div className="row">
</div>
)
}
D:/feodalapp/src/pages/player-add.tsx
TypeScript error in D:/feodalapp/src/pages/player-add.tsx(8,40):
Expected 7-8 arguments, but got 1. TS2554
6 | const [id] = useState<number>(new Date().getTime());
7 |
> 8 | const [player] = useState<Player>( new Player(id) );
| ^
9 |
10 | return (
11 | <div className="row">
I lost many time cause of TYPESCRIPT since i decided to used it in my project :: I become crazy
What did i wrong ?
thank so much