Closed jvandermey closed 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.
Also, does this actually return a Property
object? Is the dictionary equivalent to an instance?
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
Rather than using any here and wiping out any type information, check out the
Partial
typescript helper herehttps://github.com/droneshire/dealanalyzer/blob/42c14590838684bfc521270ac0ea08dae8c975ba/src/components/Property.tsx#L36