Svelte ו-TypeScript: איך להוסיף או להרחיב קומפוננטה בסיסית/ברירת מחדל כמו
או


באפליקציית Svelte שלי אני מנסה לאפשר למשתמשים להעלות תיקיות בנוסף לקבצים. עד כה הדרך היחידה שמצאתי לעשות זאת היא להשתמש בתגית input עם המאפיין type="file", ולהוסיף את המאפיין webkitdirectory, שלצערי אינו סטנדרטי. סוג הקלט של Svelte אינו כולל את webkitdirectory. הקוד פועל אבל אני מקבל את שגיאת TypeScript "Property 'webkitdirectory' does not exist on type 'SvelteInputProps'". האם אפשר להרחיב את סוגי הברירת מחדל ב-Svelte, כדי שאוכל להשתמש בתגית input כזו:

<input
  type="file"
  multiple
  webkitdirectory  <-- attribute not accepted
/>

תשובה #1

זה קצת תחבולה אבל אני השתמשתי ב-setAttribute כך:

function setAttributeWebkitdirectory(node) {
    node.setAttribute('webkitdirectory', '');
}

html :

<input
    type="file"
    use:setAttributeWebkitdirectory
/>