Rocky_Mountain_Vending/.pnpm-store/v10/files/a2/f1d34967fff27ceac39831ac5c4114ef8b0edd36d99741576eb5ba1d99c954dcf5e98fb41ebfcb2aee1ec5c0bb70349aa459ba254be5ba2e9f68c95a4deb12
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

29 lines
1.5 KiB
Text

import type {IsUnknown} from './is-unknown';
/**
Create a function type with a return type of your choice and the same parameters as the given function type.
Use-case: You want to define a wrapped function that returns something different while receiving the same parameters. For example, you might want to wrap a function that can throw an error into one that will return `undefined` instead.
@example
```
import type {SetReturnType} from 'type-fest';
type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | undefined>;
//=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
```
@category Function
*/
export type SetReturnType<Function_ extends (...arguments_: any[]) => any, TypeToReturn> =
// Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
Function_ extends (this: infer ThisArgument, ...arguments_: infer Arguments) => any ? (
// If a function did not specify the `this` fake parameter, it will be inferred to `unknown`.
// We want to detect this situation just to display a friendlier type upon hovering on an IntelliSense-powered IDE.
IsUnknown<ThisArgument> extends true ? (...arguments_: Arguments) => TypeToReturn : (this: ThisArgument, ...arguments_: Arguments) => TypeToReturn
) : (
// This part should be unreachable, but we make it meaningful just in case…
(...arguments_: Parameters<Function_>) => TypeToReturn
);