r/typescript • • Apr 17 '25

n-params vs single param

Thumbnail carlos-menezes.com
9 Upvotes

r/typescript • • Apr 18 '25

What is the most convienient way to integrate code generation?

0 Upvotes

Hi! I'm building a library that requires calling a command for typescript code generation, and I'm thinking of improving the developer experience. I want to avoid making people call a separate command while keeping the library predictable. What are my options?

The library consists of a CLI and a SDK, so one way I can think of is to call the tool automatically inside the SDK if NODE_ENV is set to development, it's kinda hacky though :) Appreciate your advice here!


r/typescript • • Apr 16 '25

How in the world do people know how to add types to things like THIS?

26 Upvotes

Hey guys, your favorite confused TypeScript beginner is back!

Somebody please explain to me how the heck is one supposed to be able to create a type like this to satisfy the TS compiler when one has no clue how the (scarcely documented) IMaskMixin even works?! How did the person in the second link come up with their convoluted-looking type AND GET IT RIGHT?! Their proposed solution works, but I have no idea why nor how they had the brains to put it together.

See, this is my major blocker/difficulty with TS. How am I supposed to know enough about the above-mentioned IMaskMixin's internals or some other third-party library to provide correct types for it? In the case of the mixin the documentation is barely existent with regard to how to use it, and the API documentation seems complete but looks really scary and completely opaque to my beginner eyes.

I feel totally lost. Typing third-party stuff feels like a huge poke-in-the-dark chore and a major pain in the ass. I feel like TS requires me to know things about third-party libraries that I'd never care to know as a user of these libraries but I must know if I want to shut up my TS compiler.

Please shed some light.


r/typescript • • Apr 16 '25

Is there a way to generate a type based off a list of values dynamically?

17 Upvotes

I'm working on something where there are literally hundreds of order codes, and new ones added and old ones removed every month. I need a type to encompass all of the order codes to enforce in our code.

Type OrderCode = "VOC" | "MLC" | "ENF" ... etc, etc, etc.

Is there a way to generate the type dynamically since it's not practical to update a giant type every month? How would you approach this?


r/typescript • • Apr 15 '25

How does one type currying functions with generics properly?

6 Upvotes

I'm trying to add strong typescript validation to an existing codebase but getting stuck on one of the functions in the project. The function uses optional currying and the typing seems to get lost. Here is the Typescript Playground link:

TypeScript Playground

This is the closest i have gotten to typing it but seems like mapObj in the last line looses its typing.
it gets inferred as

function mapObj<object>(fn: (value: never, prop: never, obj: object) => never): <U>(obj: U) => U

but i Wish for it to infer as

function mapObj<SyncConflict>(fn: (value: DirtyRaw, prop: keyof SyncConflict, obj: SyncConflict) => DirtyRaw): <SyncConflict>(obj: SyncConflict) => SyncConflict

Is this possible?


r/typescript • • Apr 15 '25

TSServer is server of what?

11 Upvotes

I know it's not an LSP server, so it's server of what actually?