打字稿如何输入类属性?

时间:2021-06-30 15:21:30

标签: reactjs typescript

我正在实现我的客户端渲染版本,我想输入我的 <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateBooksTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->string('name')->length(50)->unique(); $table->binary('image'); $table->integer('price')->unsigned(); $table->text('title'); $table->integer('quantity')->length(2)->unsigned(); $table->integer('ratings')->length(2)->unsigned(); $table->string('author'); $table->longText('description'); $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('books'); } } 对象。

其结构如下:

Books.php (model)

注意 Post 是一个未实例化的自定义类。

会有多个组件,但所有组件都将继承一个名为 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Books extends Model { use HasFactory; protected $fillable = [ 'name', 'image', 'price', 'title', 'quantity', 'ratings', 'author' , 'description' ]; protected $hidden = [ 'password', 'remember_token', 'updated_at' ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; /** * Return a key value array, containing any custom claims to be added to the JWT. * * @return array */ public function getJWTCustomClaims() { return []; } /** * Get the identifier that will be stored in the subject claim of the JWT. * * @return mixed */ public function getJWTIdentifier() { return $this->getKey(); } //inverse one to many public function user(){ return $this->belongsTo(User::class); } } 的类。有没有办法使用其父项输入 route

1 个答案:

答案 0 :(得分:1)

只需使用 typeof {ClassName}

type Route = {
 path: string,
 component: typeof BaseComponsnet
}

请记住,您可以使用 BaseComponenttypeof BaseComponent。第一个代表类实例,第二个代表类本身