我是一個新的react typecript開發者,我有一個代碼,在'js'中作業,但當改變為'tsx'時得到了錯誤。Type 'Element' is not assignable to type 'string'.ts(2322) it is pointing to 'helperTextt' 。 錯誤(在其他地方沒有找到答案) 我應該怎么做:讓helperTextt:any = "";?
任何建議?
。let helperTextt = "";
if (event.target.id == "hostname") {
if (!HOSTNAME_REGEX.test(event.target.value) {
helperTextt = (
<Trans i18nKey="form.formData.hostNameError"/span>>
無效的主機名稱
</Trans>
);
errorr = true。
}
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
你可以向你的helperTextt 變數添加型別
let helperTextt: JSX.Element = null;
uj5u.com熱心網友回復:
你可以這樣做
import { ReactElement } from "react"。
然后
let helperTextt: ReactElement | null = null;
uj5u.com熱心網友回復:
Typescript自動推斷helperTextt是一個字串,如果你確定它的值,你可以繞過這個問題(盡管不喜歡宣告type any),把它宣告為type any:
let helperTextt: any;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/309255.html
標籤:
上一篇:無法運行flutter應用程式
