facebook/idx

DeepRequiredObject causing issues in Typescript 3.5.1

Closed this issue · 2 comments

After upgrading to typescript 3.5.1 I am having issues and having to do a lot of manual casting of types.

const Users: {
    user?: {
        dateAdded: Date
    }
} = { user: { dateAdded: new Date() } };
const userDate = idx(Users, _ => _.user.dateAdded)
if (userDate) {
    new Date(userDate) // Errors - Type DeepRequiredObject<Date> is not assignable to type 'number'
}

The following will also fail:

interface UInterface {
    user?: {
        dateAdded: Date;
    };
}

const Users: UInterface = { user: { dateAdded: new Date() } };
const userDate = idx<UInterface, Date>(Users, _ => _.user.dateAdded); // This now fails with
/*
TS2741: Property '[Symbol.toPrimitive]' is missing in type 'DeepRequiredObject<Date>' but is required in type 'Date'
*/
if (userDate) {
    console.log(new Date(userDate));
}

Can you make a pull request that upgrades the TypeScript version in this repo and adds a test case that fails? We can go from there.

closing this issue as it was how I was doing my types else where. The error message in webstorm was leading me down the wrong path.

Thanks.