The fundamental difference between these two lies in how TypeScript infers types:
export const FixedInferredType = <T extends QueryRoutes>(name: T) =>: This is a generic function. The type T is inferred based on the argument passed to the function. If you call FixedInferredType("getBusinesses"), TypeScript infers that T is "getBusinesses", not just any member of QueryRoutes. This allows for more precise type checking and intellisense within the function body.
export const ParameterAsUnion = (name: QueryRoutes) =>: This is a non-generic function. The type of name is QueryRoutes, which is a union of several string literals. TypeScript only knows that name is some member of QueryRoutes, but it doesn't know which specific member it is. This results in less precise type checking and intellisense within the function body.
The fundamental difference between these two lies in how TypeScript infers types:
export const FixedInferredType = <T extends QueryRoutes>(name: T) =>: This is a generic function. The type T is inferred based on the argument passed to the function. If you call FixedInferredType("getBusinesses"), TypeScript infers that T is "getBusinesses", not just any member of QueryRoutes. This allows for more precise type checking and intellisense within the function body.
export const ParameterAsUnion = (name: QueryRoutes) =>: This is a non-generic function. The type of name is QueryRoutes, which is a union of several string literals. TypeScript only knows that name is some member of QueryRoutes, but it doesn't know which specific member it is. This results in less precise type checking and intellisense within the function body.