I am new to TypeScript and React Typescript. I have 1-3 primary syntax issues I'm working through learning right now.
I have a small component in a file called Chunk.js
import React from "react";
export function Chunk({ index, availableStylings, chunkValue }) {
return (
<span key={index} className={`stylized ${availableStylings} `}>
{chunkValue}
</span>
);
}
I want to import this file and create an array of Chunks out of it. For instance:
// prettyText.js
import { Chunk } from "./chunk/Chunk";
function prettyText(inputText: string, stylings: Array<Styling>, callback: any): Array<Chunk> {
let isStylingsEmpty = stylings.length === 0;
if (isStylingsEmpty) {
let createNonspecialChunk: any = <typeof Chunk index={0} availableStylings={null} chunkValue={inputText} />;
let nonspecialChunkArray: any[] = [createNonspecialChunk]
return (
nonspecialChunkArray
);
}
here is another part of that very same function
if (!atLeastOneWellFormedStyling) {
let createNonspecialChunk: typeof Chunk = <Chunk index={0} availableStylings={null} chunkValue={inputText} />
let nonspecialChunkArray: typeof Chunk[] = [createNonspecialChunk]
return (
nonspecialChunkArray
);
}
I wrote typeof Chunk because when I didnt have it I had an underlined red squiggle under Chunk that said 'Chunk' refers to a value, but is being used as a type here. Did you mean 'typeof Chunk'?ts(2749)
I want to have the return value be an array of Chunks. Is typeof Chunk correct? Array<typeof Chunk>?
I see lots of talk about using an interface during import of a component into React TS. I am too new to understand this and put it all together myself. Can someone explain?
The ideal answer works without me having to go make Chunk.js into a .tsx file