Replace this Size enum with an as const object, and add an isSize guard for strings that come from outside.
Existing code uses Size.Small and the Size type, and calls Object.values(Size) to fill a dropdown; all of that must keep working. A caller passing the string "small" should compile, and "huge" should not. Also add isSize(value), a type guard, so a string read from the URL or a form can be checked and then passed to label.
enum Size { Small = "small", Medium = "medium", Large = "large",} function label(size: Size): string { return size.toUpperCase();} // add: function isSize(value: string): value is Size // label(Size.Small); // "SMALL"// label("small"); // should compile too// Object.values(Size); // ["small", "medium", "large"]// const fromUrl = new URLSearchParams(location.search).get("size") ?? "";// if (isSize(fromUrl)) label(fromUrl);The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…