cf.completefrontend

Write the codeEasy

Make createState(initial) generic, so get and set use the type of the initial value.

createState keeps one value in a closure. With any, count.get() is any and count.set("1") compiles. Make the state's type come from initial, and let callers pass a wider type, such as a union of statuses, when they need one.

Write this
function createState(initial: any) {  let value = initial;  return {    get: () => value,    set: (next: any) => {      value = next;    },  };} // const count = createState(0);// count.get();    // typed number// count.set("1"); // should be a type error

Solve it in the editor

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…