具体的な例として、Express.Response.locals
のタイプをany
からアプリケーション固有のAppLocals
インターフェイスに変更しようとしています。私は@types/express
を使用しています。タイプの宣言をTypeScriptのDefinitelyTypedからどのように拡張するのですか
私が動作しているようですどれもいくつか試してみました:
declare namespace express {
export interface Response {
locals: AppLocals
}
}
はエラーを与える:Import declaration conflicts with local declaration of 'express'
は、ファイルの先頭にimport * as express from 'express'
から来ます。
私は構造を複製しようとした場合in the sourceが見つかりました:
declare global {
namespace Express {
export interface Response {
locals: AppLocals
}
}
}
その後ハンドラでexpress.Response
の地元プロパティは、まだタイプany
です。
私はちょうどそれの一体のため、これをしようとした場合:
declare namespace Express {
interface Response {
locals: AppLocals
}
}
活字体が'Express' is declared but never used
既存のプロパティのタイプを変更することはできません。プロパティを追加することはできますが、すでに設定されているプロパティは変更できません。 –