use optional method in interface as type to array

i have this interface (notice how the methods are made optional)
interface Module {
Start?(): void;
CharacterAdded?(char: Model): void;
};
interface Module {
Start?(): void;
CharacterAdded?(char: Model): void;
};
i have this array
const characterAddedFuncs: Array<Module['CharacterAdded']> = [];
const characterAddedFuncs: Array<Module['CharacterAdded']> = [];
the problem with the type of the array is that it keeps the 'optional-ability' from the type of CharacterAdded. This is causing me problems elsewhere in the code. How can I essentially omit the optional part? The current type of 'characterAddedFuncs':
const characterAddedFuncs: (((char: Model) => void) | undefined)[]
const characterAddedFuncs: (((char: Model) => void) | undefined)[]
I want it to be
const characterAddedFuncs: ((char: Model) => void)[]
const characterAddedFuncs: ((char: Model) => void)[]
2 Replies
Fireboltofdeath
NonNullable<Module["CharacterAdded"]>
CriShoux
CriShouxOP2y ago
thank you that works

Did you find this page helpful?