I've created a code snippet called MyTest
that maps over an object:
type MyTest<T> = {
[P in keyof T]: T[P];
};
type Result = MyTest<{hello: 'world', foo: 2}>;
// ^? type Result = { hello: 'world', foo: 2 } 👍
But when I input a string literal like hello
, I just get hello
back. I'm curious as to why this happens.
type Result2 = MyTest<"hello">;
// ^? type Result2 = "hello" 👀
I have two theories about what could be causing this:
- The iteration may involve keys such as
toString()
, resulting in an object with approximately 35 keys all assigned the value ofnever
. - Or perhaps the iteration doesn't occur because there's nothing to iterate on. In that case, what would the default value be?