type-fest
type-fest copied to clipboard
Add `Passthrough` type
https://github.com/sindresorhus/type-fest/pull/188
Here's a self-contained port of the use case in #188:
namespace Foo {
export interface InnerFoo {
abc: {}
}
}
type Passthrough<T> = T;
// Syntax Error
interface EnhancedAnchorProps extends Foo.InnerFoo["abc"] {
}
// Valid Syntax
interface EnhancedAnchorProps extends Passthrough<Foo.InnerFoo["abc"]> {
}
// Also valid
type abc = Foo.InnerFoo["abc"];
interface EnhancedAnchorProps extends abc {
}
While Passthrough<Foo.InnerFoo["abc"]>
in a way is prettier, I'm not convinced the utility is enough to add it to type-fest?
It's a very very basic helper + one can also just as well manually extract the type prior to extending it.
You think it has merit @sindresorhus or you haven't made up your mind yet?
I think it's worth adding it, if only to be able to document that it can be achieved without the utility too. Many of these types here are easy to implement, but what gives them value is the extensive docs.
Could be named to something more common like Same<T>
or Identity<T>
? I didn't understand what Passthrough<T>
passed through.
I prefer Passthrough
, it's easier to search for than Same
or Identity
, and this particular utility isn't exactly intuitive, so I think it should be easily searchable (because the truly intuitive thing would be for TS to just work on that directly, without this workaround).