Currently, it is possible to make setter support undefined/null and have non-undefined/non-null getter:
export interface IProperty<T> {
get value(): T;
set value(value: T | undefined);
}
// the following is ok with "strictNullChecks": true
const a: IProperty<string> = {value: ''};
a.value = undefined;
const b = a.value;
console.log(b);
I want to make a generic type that allows setting undefined for all properties of an object, see comment:
// this type works, but it also makes getter nullable :(
export type EditableObject<T> = {
[K in keyof T]: EditableObject<T[K]> | undefined;
};
This looks bad, but we need such type to start using strictNullChecks in a large app.
export function editableScope<T>(item: T, block: (item: EditableObject<T>) => void): void {
block(item);
}