|
|
|
|
|
by nyssos
696 days ago
|
|
> Do you have an anecdote (just one!) of a case where TypeScript's lack of type system soundness bit you on a real application? Sure. The usual Java-style variance nonsense is probably the most common source, but I see you're not bothered by that, so the next worst thing is likely object spreading. Here's an anonymized version of something that cropped up in code review earlier this week: const incomingValue: { name: string, updatedAt: number } = { name: "foo", updatedAt: 0 }
const intermediateValueWithPoorlyChosenSignature: { name: string } = incomingValue
const outgoingValue: { name: string, updatedAt: string } = { updatedAt: new Date().toISOString() , ...intermediateValueWithPoorlyChosenSignature }
|
|
And yes, TypeScript types are "at least these properties" and not "exactly these properties". That is by design and is frankly one reason why I like TypeScript over Java/C#/Kotlin.
I'd be very interested to know what you'd do to change the type system here to catch this. Are you proposing that types be exact bounds rather than lower bounds on what an object contains?