import Component1 from './Component1.svelte';
import Component2 from './Component2.svelte';
interface complexObject {
comp1 : Component1
comp2: Component2
}
let newComplexObj:complexObjects = {
comp1: Component1, <------ This is where error happens
comp2: Component2 <------- This is where error happens
}
型別 'typeof Component1__SvelteComponent_' 缺少型別 'Component1__SvelteComponent_' 的以下屬性:$$prop_def、$$events_def、$$slot_def、$on 和另外 5 個.ts(2740)
這些是我的打字稿配置:
"compilerOptions": {
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictBindCallApply": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strict": true,
"importsNotUsedAsValues": "preserve"
}
它確實在瀏覽器中正確呈現,并且在運行時我沒有收到任何錯誤,但在 IDE 中它向我顯示了該錯誤。
uj5u.com熱心網友回復:
您不是在設定實體,而是在設定建構式,即typeof.
interface complexObject {
comp1: typeof Component1,
comp2: typeof Component2,
}
(順便說一下,這是錯誤訊息的一部分,但很容易在所有噪音中錯過。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/489450.html
