Jest to typ generyczny z TypeScript https://www.typescriptlang.org/docs/handbook/2/generics.html
interface FileList {
id: number;
name: string;
author?: string;
}
// ...
// ...
const [file, setFileList] = useState<FileList | null>(null);
i teraz TypeScript oznaczył, że zmienna file
, lub argument setFileList
może być obiektem, lub nullem
setFileList(null); // okej
setFileList({}); // błąd
setFileList({ id: 10 }); // błąd, bo brakuje właściwości name
setFileList({ id: 11, name: 'foo' }); // okej
setFileList({ id: 11, name: 'foo', author: 'bar' }); // okej, bo właściwość author jest dobrowolna i nie trzeba zawsze jej podawać
Podobne błędy pojawią się przy zmiennej file
jeśli skorzystamy z niej w zły sposób.