In the code below, I specified that setLocale should receive a value of type Locale as a parameter via LocaleContextValue.
But why doesn’t the setLocale function throw an error if I don’t pass any value as a parameter?
Even if I make it return a string type like () => { return “hello” }, it doesn’t throw any error.
import { createContext, ReactNode, useContext, useState } from "react";
type Locale = "ko" | "en";
interface LocaleContextValue {
locale: Locale;
setLocale: (value: Locale) => void;
}
const LocaleContext = createContext<LocaleContextValue>({
locale: "ko",
setLocale: () => {},
// setLocale: () => { return "hello"; },
// No errors occurred.
});
New contributor
BMAIL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.