Closed PCOffline closed 10 months ago
Todo: update readme
Please read the section in the readme that describes why we won't make this change.
Alright, didn't see it in the GitHub Readme. Makes sense though
Please read the section in the readme that describes why we won't make this change.
@mattpocock This seems to be gone from the README. Could you add the note here?
Found it:
Object.keys
/Object.entries
A common ask is to provide 'better' typings for Object.keys
, so that it returns Array<keyof T>
instead of Array<string>
. Same for Object.entries
. ts-reset
won't be including rules to change this.
TypeScript is a structural typing system. One of the effects of this is that TypeScript can't always guarantee that your object types don't contain excess properties:
type Func = () => {
id: string;
};
const func: Func = () => {
return {
id: "123",
// No error on an excess property!
name: "Hello!",
};
};
So, the only reasonable type for Object.keys
to return is Array<string>
.
Bruh this issue was closed 3 months ago how'd you even find it
Intro
This type changes the behaviour of
Object.entries
to return more specific types:Caveats
const
keyword for more specific results. Therefore, the difference between the results ofObject.entries
in TypeScript 5 would be even bigger, since theas const
part would be omitted. In earlier versions, for specific results, theas const
assertion needs to be added to inputs.Object.entries
cannot be relied on, therefore a union of tuples is returned instead of a deterministic tuple (i.e.(["a", 1"] | ["b", 2])[]
and not[["a", 1], ["b", 2]]
)