3 ms·
I actually don't really like Record types in the way people/library maintainers often use them - the type-checker asserts that values are actually present for a
by presentation 5y ago
I actually don't really like Record types in the way people/library maintainers often use them - the type-checker asserts that values are actually present for all the specified keys, which is fine if the objects with the Record type really were exhaustive; but instead I often see them used where the reality of the data is a Partial<Record> - some keys are missing. Something about the abstraction causes people to misuse it frequently.
- e1g 5y agoYep, and in your own code you can tell TS to verify your property access with the setting `noPropertyAccessFromIndexSignature` (https://devblogs.microsoft.com/typescript/announcing-typescript-4-2/#no-property-access-index-signature https://devblogs.microsoft.com/typescript/announcing-typescr...) The TS crew did discuss having a "pedantic" mode, which is stricter than "strict", but I don't think it's on the roadmap any more.
- jsf01 5y agoThat one as well as the noUncheckedIndexedAccess ought to be defaults when in strict mode.
- bilalq 5y agoYou pretty much always have to define your record type with `| undefined` tacked on to the value type parameter. With that, the problem mostly goes away.
- lugged 5y agoWhat's the point of typing things if you have to constantly typecheck them anyway?
- presentation 5y agoYeah, but I use libraries that don’t do that, and have teammates that don’t care about this