droneshire / dealanalyzer

Analyze deals using in PA
0 stars 0 forks source link

Partial types #11

Closed jvandermey closed 1 year ago

jvandermey commented 1 year ago

Rather than using any here and wiping out any type information, check out the Partial typescript helper here

https://github.com/droneshire/dealanalyzer/blob/42c14590838684bfc521270ac0ea08dae8c975ba/src/components/Property.tsx#L36

droneshire commented 1 year ago

Nice. Also is there a better native way of assigning these? In python this could be all done in a for loop.

droneshire commented 1 year ago

Also, does this actually return a Property object? Is the dictionary equivalent to an instance?

jvandermey commented 1 year ago

Sorry, forgot to come back to these. You may have already figured this out, but the type interfaces are just hints, they aren't real types. Javascript does (sort of) support classes, but ultimately everything (even class instances and things like arrays) are just objects (like a dict, but a little looser). So this just returns an object that adheres to that interface. It can still have more attributes on it as well, as long as it satisfies the interface.

On the note of arrays being object, you can do things like this without errors (since JS doesn't throw errors for missing object key access, it just returns undefined).

const foo= [1, 2];
console.log(foo[1])
>> 2
console.log(foo[2])
>> undefined
console.log(foo["bar"])
>> undefined