abi
abi12mo ago

Type alias with inherited type parameter constraints

Is there any way to do this? I want SVLTN to just be a short-name alias for SomeVeryLongTypeName, and I want it to have the same parameter types, but I don't want to have to specify all of them explicitly.
type SomeVeryLongTypeName<A extends ..., B extends ..., ...> = ...
type SVLTN<A extends ..., B extends ..., ...> = SomeVeryLongTypeName<A, B, ...>
type SomeVeryLongTypeName<A extends ..., B extends ..., ...> = ...
type SVLTN<A extends ..., B extends ..., ...> = SomeVeryLongTypeName<A, B, ...>
What I would like more is:
type SVLTN = SomeVeryLongTypeName<???>
type SVLTN = SomeVeryLongTypeName<???>
Anyone?
6 Replies
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
TheYuriG
TheYuriG12mo ago
if both of the types are yours, this is a horrible idea for maintainability, you would have 2 things pointing to the same thing. long variable names are fine if it's coming from outside, then you can just import as, like sno2 mentions
abi
abi12mo ago
i disagree that it's a "horrible idea for maintainability", why would you say that?
TheYuriG
TheYuriG12mo ago
because it makes the maintainer need to know that A = B and B = B when they could just know that B = B and settle with that. adds another layer of knowledge that doesn't need to exist
abi
abi12mo ago
🤷‍♂️ i guess it all depends. this is something that borders on a DSL, and the "real alias" reads like an acronym rather than "SVLTN", but point taken!
AapoAlas
AapoAlas12mo ago
You can also do sno's aliasing in a re-export declaration: export type { Long as L } from "./long.ts."; Or simply an export declaration export { Long as L };