type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Add `Passthrough` type

Open sindresorhus opened this issue 3 years ago • 4 comments

https://github.com/sindresorhus/type-fest/pull/188

sindresorhus avatar Jul 08 '21 11:07 sindresorhus

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?

voxpelli avatar Sep 22 '21 21:09 voxpelli

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.

sindresorhus avatar Sep 24 '21 14:09 sindresorhus

Could be named to something more common like Same<T> or Identity<T>? I didn't understand what Passthrough<T> passed through.

fregante avatar Sep 25 '21 07:09 fregante

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).

papb avatar Jan 19 '22 17:01 papb