#Difference between partial objects

5 messages · Page 1 of 1 (latest)

ornate hedge
#

Hi all, is there any difference between these types? I am defining them in slightly different ways and they seem to behave the same, but the mouseover tooltip in VS Code is printing them differently. They seem to behave the same as far as I can test

{
    name: string | undefined;
    email: string | undefined;
    age: number | undefined;
}
{
    name?: string | undefined;
    email?: string | undefined;
    age?: number | undefined;
}
#

This is a simplified example, in reality what I'm doing is making a deeply-nested partial of sorts

empty oak
#

optional properties can be omitted completely.

magic burrowBOT
#
const x: { x?: undefined } = {}
const y: { y: undefined } = {}
//    ^
// Property 'y' is missing in type '{}' but required in type '{ y: undefined; }'.
ornate hedge
#

Ah I see, makes sense now. The way I was testing it was unsufficient which had me confused. Thanks @empty oak