Asking this here because not sure how to phrase it properly so google understands.
I have a utility function to capitalize words in a string, that as a second argument can get passed an options object:
export type Options = {
onlyFirstWord?: boolean;
separator?: string;
};
const defaultOptions = {
onlyFirstWord: false,
separator: " ",
};
export default function capitalize(
str: string,
options: Options = defaultOptions
) {}
So the second argument is optional, since I've provided a default value for it, but if I make the properties optional in the type, it requires me to check if those are undefined or not, even though they 100% can never be undefined, because of the default value. But if I don't make them optional, I will have to enter every single property when passing the options object, otherwise it would give an error.
I know there is a lot of similar questions, but in this case, is there no way to tell typescript that those values are never undefined, other than having to put exclamation marks or use optional chaining? Shouldn't it automatically figure out that they are never undefined since I'm providing a default value for it? Thanks and do let me know if this is a duplicate and this has already been answered.