Required<T>
Constructs a type with all properties of T set to required.
Syntax
Required<Type> Returns
object type — A new type identical to T but with every optional property made required.
Examples
interface Props {
a?: number;
b?: string;
}
const obj: Required<Props> = { a: 1, b: 'x' };
type Settings = { theme?: string; debug?: boolean };
function applyAll(s: Required<Settings>) {
console.log(s.theme, s.debug);
}
Notes
Removes the `?` modifier from every property using a `-?` mapped type. Shallow
only; nested optional members remain optional. It also strips `undefined` that
was added implicitly by the optional modifier, but not explicit `| undefined`
unions in property types.