#Optional type inference. Why?

3 messages · Page 1 of 1 (latest)

worn wharf
#
const mkSchema = (isC: boolean) => {
    return {
        a: "test",
        b: 23,
        ...(isC ? {c: "whatever"} : {})
    }

}

const a = mkSchema(true)
const b = mkSchema(false)

Hi. Why do the types of a and b are infered like

a: {
    c?: string | undefined;
    a: string;
    b: number;
} 

I expected to see c?: string instead.

weary kiln
#

See exactOptionalPrppertyTypes option in tsconfig.

worn wharf
#

thanks