abi
abi2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
TheYuriG
TheYuriG2y 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
abiOP2y ago
i disagree that it's a "horrible idea for maintainability", why would you say that?
TheYuriG
TheYuriG2y 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
abiOP2y 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
AapoAlas2y 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 };

Did you find this page helpful?