Why aren't fields in Record optional?

时间:2019-01-15 18:08:50

标签: typescript typescript-typings typescript2.0

Currently, Record<K, T> is defined as:

type Record<K extends keyof any, T> = {
    [P in K]: T;
};

Why isn't it defined as:

type Record<K extends keyof any, T> = {
    [P in K]?: T;
};

That seems like it would be safer, because in most cases you would need to verify that a particular key existed on the object before you could go ahead and read it.

0 个答案:

没有答案