Comment

Comment by com2kid

TypeScript aims to make a type system that can model anything you can do in JS. Of course JS can modify its objects, at runtime, in literally any way imaginable, so the TS type system has to be Turing complete. Anything less powerful and you aren't going to be able to model what arbitrary JS code is doing.

My go to example being a function that takes in an object with a bunch of camel case parameterFields and makes them into snake case parameter_fields.

Easy peasy in TypeScript, You can say, in a generic fashion, "pass an object with camelCase field names, and return the same object but the field names are snake_case".

This is incredibly useful when adapting between different systems!

Traditional OO systems fall flat on their face attempting such feats.

parent com2kid 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton