r/typescript • u/unclejoessheds • Nov 08 '25
TypeScript Just Dethroned Python and JavaScript on GitHub
r/typescript • u/unclejoessheds • Nov 08 '25
r/typescript • u/void5253 • Nov 08 '25
const COMMON_COLS = { EMAIL: 2, FN: 3, LN: 4, SUBJ: 6, TOPIC: 8 };
const RESP_COLUMN_CONFIG = {
A: {
...COMMON_COLS,
TZ: 7,
REG: {
IST: 9,
UAE: 10,
HKT: 11,
UK: 12,
AST: 13,
},
},
I: {
...COMMON_COLS,
TZ: 9,
MATH: 7,
REG: {
IST: 10,
UAE: 11,
HKT: 12,
UK: 13,
ET: 16,
AST: 17,
},
},
} as const;
type RespColType = keyof typeof RESP_COLUMN_CONFIG;
function getResponseCols(columnType: RespColType) {
return RESP_COLUMN_CONFIG[columnType];
}
function resolveDate(tz: string, data: string[], isALevel: boolean) {
const respCols = getResponseCols(isALevel ? "A" : "I");
let tzKey: keyof typeof respCols.REG = "IST";
if (tz.includes("ist")) tzKey = "IST";
else if (tz.includes("uae")) tzKey = "UAE";
else if (tz.includes("singapore")) tzKey = "HKT";
else if (tz.includes("uk")) tzKey = "UK";
else if (tz.includes("ast")) tzKey = "AST";
else if (tz.includes("et")) {
if ("ET" in respCols.REG) tzKey = "ET";
}
}
in resolveDate, the last else if is giving "ET" not assignable to type "IST" | "UK" | ... error.Any help on why this is the case will be appreciated.
r/typescript • u/AppealNaive • Nov 07 '25
Over the past year and a half, I’ve been exploring how far we can push TypeScript’s inference engine while building an open-source framework and CLI — with the goal of keeping everything fully type-safe yet flexible at runtime.
It started with a simple question: Could type contracts serve as the single source of truth for validation, coercion, and SDK generation?
Here are a few learnings that stood out:
.ts files scales poorly..d.ts) in the background with tsc -w restores near-instant inference, suggesting that pre-serialized types dramatically improve developer experience.I’d love to hear how others handle similar trade-offs:
.d.ts or rely entirely on live inference?I’ve open-sourced the framework and CLI (link in the first comment) and would be happy to share benchmarks or implementation details if anyone’s curious.
r/typescript • • Nov 08 '25
Hi! I want to change all my React projects from .jsx to .tsx. any youtube channel or web page you recommend for doing this?
Thanks!
r/typescript • u/Entrance_Brave • Nov 06 '25
I built a website that categorizes JS/TS packages for frameworks in categories. If anybody else finds it useful I'm happy....
It also shows if a packages has TypeScript Types included or if there's Types available via DefinitelyTyped
https://www.stacktco.com
r/typescript • u/MorroWtje • Nov 06 '25
r/typescript • u/pie6k • Nov 04 '25
I've been working on Codables, a JSON serialization library that extends JSON to handle complex JavaScript types with a declarative, decorator-based approach.
Interactive Playground - Test your own data structures
For declarative class serialization:
@codableClass("Player")
class Player {
@codable() name: string;
@codable() score: number;
}
const encoded = encode(data);
const decoded = decode(encoded);
// All types preserved!Would love feedback from the TypeScript community!
r/typescript • u/Swimming-Jaguar-3351 • Nov 04 '25
I'm busy refactoring a VueJS SPA, and am seeing surprising behaviour from a Map. I'd like to better understand what is happening here, it seems to show a significant hole in my understanding of Typescript/Javascript. Maybe this is a pure Javascript problem, but I couldn't yet rule out `===` being tweaked by the Typescript type system.
This code is a stepping stone between an old design and a new design. I'm moving conversation comments out of Conversation objects and into a Map indexed by conversation docId's, such that Conversation objects can be "plain old data" without arrays. This is a method of a Repository class:
const conv = new Conversation(/* ... */);
// Extracting the comments in question:
const convComments: Array<Comment> = conv.comments;
// I'm moving comments into this map:
const commentsIndex: Map<string, Array<Comment>> =
this._conversationsCommentsIndex;
// Setting the value to the Array:
commentsIndex.set(conv.docId, convComments);
// Grabbing the value from the Array, to check:
const checkVal = commentsIndex.get(conv.docId);
// Dropping "undefined" from checkVal's type:
if (checkVal === undefined) {
throw new Error('FIXME(data): how did checkVal end up undefined?');
}
// Here's the surprising result
// I don't understand why this happens:
if (checkVal !== convComments) {
console.log(
'FIXME(data): how is it that checkVal !== convComments?',
'checkVal:',
checkVal,
'convComments:',
convComments,
);
// Logging output is: "checkVal: [] convComments: []"
// I wondered whether I had a reactive proxy (from VueJS):
console.log('conv type:', conv.constructor.name);
console.log('commentsIndex type:', commentsIndex.constructor.name);
console.log(
'this._conversationsCommentsIndex type:',
this._conversationsCommentsIndex.constructor.name,
);
console.log('this type:', this.constructor.name);
// Logging output is:
// conv type: Conversation
// commentsIndex type: Map
// this._conversationsCommentsIndex type: Map
// this type: EphemeralRepository
// ...
}What am I missing about checkVal !== convComments? I would expect these two to be handles to the exact same array, such that === evaluates to true.
r/typescript • u/muneebh1337 • Nov 04 '25
TypeScript Backend Toolkit V2 is available now.
Try it out "pnpm dlx create-tbk-app" (Go Full-Featured)
Docs? If you’ve worked with Express.js, you already know it, or you can just ask your AI agent or just visit > https://tstoolkit.themuneebh.com
Enjoy.
Don't forget to share your feedback.
r/typescript • u/KickAffectionate7933 • Nov 04 '25
Hey everyone,
I've been rewriting WordPress/WooCommerce with Rust backend and TypeScript frontend (no frameworks - just Rust and TypeScript). The project is nearly complete, so I am doing the last bits, and it's time for the text editor, for both the product page and the CMS.
The Problem:
I know nothing about text editors.
I did a quick search and the only truly viable solution I found was Lexical (by Meta) or ProseMirror. But I don't know what I don't know.
Technical Context:
I'm comfortable coding complex features myself, I don't necessarily need a plug-and-play solution. I'm more concerned about choosing the right editor that I can alter if needed so it has reusable blocks, product tables etc.
Can be Rust (WASM) or TypeScript.
So if someone knows text editors, I'd really appreciate any insights or alternative suggestions.
r/typescript • u/ferion • Nov 03 '25
Hey! 👋
I wanted to share a key feature of a new MIT open-source backend framework I just released for TypeScript called JS20 (https://js20.dev).
With a single line of code you can get all CRUD endpoints for a single database model automatically:app.addCrudEndpoints(models.car);
This will give you:
GET /car
GET /car/:id
POST /car
PUT /car/:id
DELETE /car/:idUnder the hood, it is equivalent to doing this:
async function requireId(req: Request) {
const id = req.params.id;
if (!id) throw new Error('ID is required');
return id;
}
async function loadCar(req: Request, action: 'read' | 'update' | 'delete') {
verifyLoggedIn(req);
const id = await requireId(req);
const existing = await prisma.car.findUnique({
where: { id, ownerId: req.user.id }
});
if (!existing) throw new Error('Car not found');
verifyACL(req.user, action, existing);
return existing;
}
async function createCar(req: Request) {
verifyLoggedIn(req);
verifyACL(req.user, 'create');
const input = validateAndSanitize(req.body, carSchema);
const newCar = await prisma.car.create({
data: {
...input,
ownerId: req.user.id,
createdAt: new Date(),
updatedAt: new Date()
}
});
validate(newCar, Schema.withInstance(carSchema));
return newCar;
}
async function getCar(req: Request) {
const existing = await loadCar(req, 'read');
validate(existing, Schema.withInstance(carSchema));
return existing;
}
async function listCars(req: Request) {
verifyLoggedIn(req);
verifyACL(req.user, 'list');
const take = Math.min(parseInt(String(req.query.take ?? '50'), 10) || 50, 100);
const cursor = req.query.cursor ? { id: String(req.query.cursor) } : undefined;
const cars = await prisma.car.findMany({
where: { ownerId: req.user.id },
orderBy: { createdAt: 'desc' },
take,
...(cursor ? { skip: 1, cursor } : {})
});
cars.forEach(c => validate(c, Schema.withInstance(carSchema)));
return cars;
}
async function updateCar(req: Request) {
verifyLoggedIn(req);
const id = await requireId(req);
const input = validateAndSanitize(req.body, carSchema);
const existing = await prisma.car.findUnique({
where: { id, ownerId: req.user.id }
});
if (!existing) throw new Error('Car not found');
verifyACL(req.user, 'update', existing);
const newCar = await prisma.car.update({
where: { id, ownerId: req.user.id },
data: {
...existing,
...input,
updatedAt: new Date()
}
});
validate(newCar, Schema.withInstance(carSchema));
return newCar;
}
async function deleteCar(req: Request) {
const existing = await loadCar(req, 'delete');
const deleted = await prisma.car.delete({
where: { id: existing.id, ownerId: req.user.id }
});
return { id: deleted.id, status: 'deleted' };
}If you need additional business logic before/after inserts, you can pass an action:
const assertMaxCarsPerUser = app.action({
outputSchema: {
count: sInteger().type(),
message: sString().type(),
},
run: async (system) => {
// Your logic here
}
});
app.addCrudEndpoints(models.car, {
actions: {
// Run assertMaxCarsPerUser action before creating a car
createBefore: assertMaxCarsPerUser,
}
});Let me know if this can be improved in any way please!
r/typescript • u/ShatteredTeaCup33 • Nov 02 '25
I have an idea for a simple web application (Flask for backend and Typescript+HTML+CSS for frontend), and first I was thinking about using React+Vite, but then I thought that vanilla Typescript might be enough.
But now to the question: since you get all the necessary config files and ESLint when you create a React project, do I have to manually add these myself now? Is it enough to use ' npx tsc --init'? Should I just use React?
r/typescript • u/romeeres • Nov 02 '25
Hi folks, here is a new library for IoC.
It's designed for modular structure and having modules as in Nest.js, but to be used for factory functions instead of classes.
Github: https://github.com/romeerez/iocta
How it looks: module and a service that injects dependencies.
Goals:
I couldn't find an existing library to provide this, let me know if it exists.
How do you like it?
r/typescript • u/PUSH_AX • Nov 01 '25
The monthly thread for people to post openings at their companies.
* Please state the job location and include the keywords REMOTE, INTERNS and/or VISA when the corresponding sort of candidate is welcome. When remote work is not an option, include ONSITE.
* Please only post if you personally are part of the hiring company—no recruiting firms or job boards **Please report recruiters or job boards**.
* Only one post per company.
* If it isn't a household name, explain what your company does. Sell it.
* Please add the company email that applications should be sent to, or the companies application web form/job posting (needless to say this should be on the company website, not a third party site).
Commenters: please don't reply to job posts to complain about something. It's off topic here.
Readers: please only email if you are personally interested in the job.
Posting top level comments that aren't job postings, [that's a paddlin](https://i.imgur.com/FxMKfnY.jpg)
r/typescript • u/voja-kostunica • Oct 31 '25
This is the original RequestResult type. I want to reuse it to create reduced ApiResult type by awaiting it and removing response prop.
export type RequestResult<
TData = unknown,
TError = unknown,
ThrowOnError extends boolean = boolean,
> = ThrowOnError extends true
? Promise<{
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
response: Response;
}>
: Promise<
(
| {
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
error: undefined;
}
| {
data: undefined;
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
}
) & {
response: Response;
}
>;
Practically I want this type:
export type ApiResult<
TData = unknown,
TError = unknown,
ThrowOnError extends boolean = boolean,
> = ThrowOnError extends true
? {
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
}
:
| {
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
error: undefined;
}
| {
data: undefined;
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
};
Important thing about tis type is that it cant have data and error props at same time, but only one of them. So when I say const initialState: ApiResult = {data: undefined, error: undefined} I should get an error that error prop shouldnt be there if data already exists.
I dont want to duplicate and repeat RequestResult definition but to reuse it and that is where I struggle. I tried this, but this fails, because both data and error are requred props at same time.
export type ApiResult<
TData = unknown,
TError = unknown,
ThrowOnError extends boolean = false,
> = Omit<Awaited<RequestResult<TData, TError, ThrowOnError>>, 'response'>;
How do I do this?
r/typescript • u/Poxnox • Oct 30 '25
I have created a library for typescript utility functions implemented in a type-safe way. Please contribute, have opinions or criticize my potentially shitty code. I'm looking to replace lodash and other general utility function libraries with a better one.
r/typescript • u/WaBeY33 • Oct 30 '25
Hello, please i feel like this is somehow common practice which i can not figure out... create() function will always be executed right after constructor. I just want to use life-cycle methods instead of constructor and keep error about variables which were not initialized... Is this possible or am i just completely off with this one... I just want to tell typescript that create will be always executed...
NOTE: i know type! works but i want non assigned error if variable was not assigned in create function
export default class GameplayScreen extends BaseScreen
{
private type: Number; //<---- Property 'type' has no initializer and is not definitely assigned in the constructor
public create(): void
{
this.type = 0;
}
}EDIT: I coppied wrong error message for //comment
EDIT2: Aight, i ll stick to constructors, i guess i am just manifesting a problem here... Thanks for advices
r/typescript • u/incutonez • Oct 29 '25
I'm trying to do something like this:
interface ComponentProps {
load: <T>() => Promise<T>;
}
interface MyData {
name: string;
}
interface MyData2 {
firstName: string;
}
async function getData() {
return new Promise<MyData[]>((resolve, reject) => {
resolve([{
name: "John"
}])
})
}
async function getData2() {
return new Promise<MyData2[]>((resolve, reject) => {
resolve([{
firstName: "John"
}])
})
}
const props: ComponentProps[] = [{
load: () => getData()
}, {
load: () => getData2()
}]
// data's type should be MyData[]
const data = await props[0].load();
// data2's type should be MyData2[]
const data2 = await props[1].load();
export {}
Basically, I want the response from my actual load property to be inferred, so it can be generic and used for any other get function that I use. I also don't want to have to define the type on ComponentProps , and that's because I'm actually defining an array of these interface objects, so that gets a little nasty. I definitely know I'm doing something wrong, but I don't know what it is. Any help would be appreciated!
r/typescript • u/ssalbdivad • Oct 28 '25
Hey everyone! I've been working on this for a while and am exciting it's finally ready to release.
The premise is simple- swap out the RegExp constructor or literals for a typed wrapper and get types for patterns and capture groups:
import { regex } from "arkregex"
const ok = regex("^ok$", "i")
// Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>
const semver = regex("^(\\d*)\\.(\\d*)\\.(\\d*)$")
// Regex<`${bigint}.${bigint}.${bigint}`, { captures: [`${bigint}`, `${bigint}`, `${bigint}`] }>
const email = regex("^(?<name>\\w+)@(?<domain>\\w+\\.\\w+)$")
// Regex<`${string}@${string}.${string}`, { names: { name: string; domain: `${string}.${string}`; }; ...>You can read the announcement here:
https://arktype.io/docs/blog/arkregex
Would love to hear your questions about arkregex or my broader abusive relationship with TypeScript's type system.
r/typescript • u/BenchEmbarrassed7316 • Oct 29 '25
Hello!
I'm trying to create something like DeepReadonly and mutability and immutability from Rust. I only use structures that are composed of other structures, scalar types, or standard collections (Array, Map, and Set), no methods. I'm getting an unpleasant error.
export type Immutable<T> =
T extends Function | string | number | boolean | bigint | symbol | undefined | null ? T :
T extends ReadonlyArray<infer U> ? ReadonlyArray<Imut<U>> :
T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Imut<K>, Imut<V>> :
T extends ReadonlySet<infer U> ? ReadonlySet<Imut<U>> :
T extends object ? { readonly [K in keyof T]: Imut<T[K]> } :
T;
export type Mutable<T, M extends boolean> = M extends true ? T : Immutable<T>;
interface Obj { some: number }
interface A {
num: number,
obj: Obj,
arr: number[],
}
function num<M extends boolean>(self: Mutable<A, M>): Mutable<number, M> {
return self.num; // ok
}
function obj<M extends boolean>(self: Mutable<A, M>): Mutable<Obj, M> {
return self.obj; // ok
}
function arr<M extends boolean>(self: Mutable<A, M>): Mutable<number[], M> {
let a = [] as Mutable<number[], true>; // : number[]
let b = [] as Mutable<number[], false>; // : readonly number[]
let c = [] as Mutable<number[], true> | Mutable<number[], false>; // number[] | readonly number[]
let d = self.arr; // number[] | readonly number[]
return self.arr; // error: Type 'number[] | readonly number[]' is not assignable to type 'Mutable<number[], M>'.
}
function arrEx<M extends boolean>(self: Mutable<A, M>): Mutable<A, M>['arr'] {
return self.arr; // ok
}
So TypeScript is actually complaining that the type number[] | readonly number[] does not assignable to number[] | readonly number[]. Moreover, if you do not specify this type explicitly and ask to display this type as a property by a specific key - there are no errors.
I try to avoid casting types as instructions.
Can anyone give any tips?
Thanks!
r/typescript • u/BCsabaDiy • Oct 29 '25
JavaScript and the NPM ecosystem feel radically different compared to the old-school world of paid programming languages and IDEs.
r/typescript • u/ferion • Oct 28 '25
Hey! 👋
In the last 8+ years I've been tinkering with a backend framework that let's you build backends with a fraction of the code that is normally needed - and then generate the frontend SDK automatically. This framework has been the core of several products I've launched, but today I'm happy to share I've made the framework fully open-source!
In the era of AI and huge computational costs from LLMs I think initiatives that reduce the code base size are crucial in lowering capacity needs, token costs & environmental impact. Let AI focus on business logic, not implementation details.
Made with love 🧡 Let me know what you think!
r/typescript • u/goguspa • Oct 27 '25
I wanted to share a project I built from the ground up with TypeScript's type system at its core: Flowcraft. It's a lightweight workflow engine for orchestrating complex, asynchronous workflows.
My main goal was to create an amazing developer experience for a notoriously difficult problem. Managing state, dependencies, and control flow in multi-step processes can quickly turn into any-hell. Flowcraft solves this with a strongly-typed API.
createFlow<MyContext>() builder is generic, giving you full type safety and autocompletion when you access state in any node.ILogger, ISerializer, Middleware, etc.) are fully typed. When you write middleware, for example, the context argument is correctly typed, so you can interact with the workflow state safely. Even the distributed adapters maintain this, using an IAsyncContext<TContext> interface.createStepper utility for step-by-step debugging gives you access to the fully-typed WorkflowState<TContext> after each step, so you can write powerful, type-safe assertions in your tests..toGraphRepresentation() method returns a typed UIGraph object. This makes it safe and predictable to integrate with UI libraries like xyflow to build visual flow editors, as your frontend and backend can share the same types.If you enjoy working with well-typed libraries that offer a nice DX, I’d love for you to check it out:
https://flowcraft.js.orghttps://github.com/gorango/flowcraft