This question is similar to:
Check if an object property is optional
However the answer given there relies on undefined extends
which is not reliable (the behavior changes if strict mode is enabled vs. disabled).
For example:
type x = {
a?: string
b: number
}
type aOptional = undefined extends x["a"] ? true : false // true strict mode on, true strict mode off
type bOptional = undefined extends x["b"] ? true : false // false strict mode on, true strict mode off
This is problematic since strict mode is off by default, which means this will be broken by default.
Assuming it is possible, how can I achieve the same thing in a strict mode agnostic way?
(we can close this question and update the other if it’s possible)