Help with strictNullChecks
This is a simplified example of the problem I'm having:
type Options = { foo: string bar: string }
type TestType<T> = { makeAString?: (a: T) => string, makeANumber?: (a: T) => number }
type ParentType<T = Options> = { aaa?: TestType<T> bbb?: TestType<T> }
function wrapFunctions<T extends Record<string, any>>(obj: T): T { return { ...obj }; }
//const r: ParentType = { // This works when strictNullChecks is false const r: Required<Pick<ParentType, 'aaa'>> = { // Have to do this when strictNullChecks is true aaa: wrapFunctions({ makeAString: ({ foo, bar }) => foo + bar, makeANumber: ({ foo, bar }) => foo.length + bar.length }) };
console.log(r); console.log(r.aaa?.makeAString?.({ foo: 'foo', bar: 'bar' }));
With `strictNullChecks` false I can get all the proper typing on the `makeA*` functions, but with it true I have to explicitly pick which properties of `ParentType` I am providing.
If that's what I have to do, so be it, but I'm hoping there's a neater way somehow where I don't have to run everything through `Pick` and `Required`.