# Value Proposition
The space of [[Transcompilers|transpilers]] and "language on top of another language" was getting popular. Some of it was from necessity. The browser-[[JavaScript]] ecosystem required bundling.
# Competitions (back then)
Now, TypeScript is the de-facto winner of the JavaScript ecosystem, but there were few competitions:
## [Google Closure Compiler](https://developers.google.com/closure/compiler/)
Closure was really difficult to use; the [highest compilation level](https://developers.google.com/closure/compiler/docs/compilation_levels) (`ADVANCED_OPTIMIZATIONS`) performs symbol renaming. This was quite disruptive. Moreover, it is questionable how much efficiency is obtained by this. I know that this idea isn't totally crazy as [[ORM]]s for MongoDB has the same feature for BSON as the benefit of shrinking disk serialized BSON is obvious.
## [Facebook Flow](https://github.com/facebook/flow)
> [!TODO] Learn about Flow
## [[CoffeScript]]
# Types
## `type` vs `interface`
TypeScript has two ways to define `type` and `interface`. They have quite a different syntax, even though they are similar.
```typescript
type Point = { x: number ; y: number }
interface Point { x: number ; y: number; }
```
`interface Child extends Parent` can be implemented via `type Child = { ... } & Parent`. In general, `type` feel more flexible, as it can be used to define union types.
```typescript
type X = "foo" | "bar"
// no interface equivalent.
```
https://www.typescriptlang.org/play#example/types-vs-interfaces
You cannot `extend` from a `type`, but an `interface` can be used within the type definition.
> [!quote] [Stack Overflow](https://stackoverflow.com/questions/37233735/interfaces-vs-types-in-typescript/52682220#52682220)
> One major difference between type aliases vs interfaces are that interfaces are open and type aliases are closed. This means you can extend an interface by declaring it a second time.
## Branded Types
> [!note] See [[Typescript - Advanced Types#Branded Types]]
```typescript
type UserId = number & { __brand: 'user_id' };
```
# Typescript-only stack
[TypeScript is the only programming language you need](https://dev.to/ixartz/typescript-is-the-only-programming-language-you-need-to-learn-one-language-to-rule-them-all-1jb9)
## [[tsx]]
- `#!/usr/bin/env node --loader tsx/esm` to trigger tsx.
## Typescript-driven programming
[[2024-12-25]] - there's certain style of programming that typescript encourages.
- plain JS objects.
- avoid classes, or even methods;
- this in turns makes things like decorators, proxy objects, and ActiveRecord-esque ORMs very rare in TypeScript.
- not much magic that cannot be expressed by the type system (though, a lot of magic can be expressed by the type system).
- magic that is expressed by the type system (ex: [[ORM]]s).
# Other Knowledge Base
> [!note]
> See [[Typescript - Advanced Types]] also.
## `asserts` versus Type Guards
## Type-only imports
Many libraries depend on this behavior;
- libraries like [[NextJS]] that mixes the backend and frontend have frontend and backend code mixed in ([[React]]'s server component contributes to this).
- [[tRPC]] - server and client can share types.
- [[Temporal]]'s typescript SDK utilizes this. Specifically, `proxyActivities` is quite magical and it abuses a lot of things to make it work.
- [[JSON]] plays an important role here as JSON can be transported without any explicit encoding / decoding, working really well in this type-erasure based world.
## [[Tree-shaking]]'s importance
## "Legacy" Features versus type-only features
[[TypeScript - Erasable]]
> [!warning]
> These are not "deprecated" per se, but is heavily discouraged in new Typescript codebase.
https://www.totaltypescript.com/books/total-typescript-essentials/typescript-only-features
- **Namespaces** - this is before [[ESM & CJS Modules]], and it behaves poorly
- **Enums** - [[Typescript - String Unions]] are recommended over enums
## use `(...args: any) => any` as function types
This is what `Parameter`, `ReturnType` uses behind the scene.
# Releases
History - Version 0.8 was released in October, 2012.
## Typescript 7 - [[Go]] native port
- https://devblogs.microsoft.com/typescript/typescript-native-port/
>[!quote]
>For the sake of clarity, we’ll refer to them simply as TypeScript 6 (JS) and TypeScript 7 (native), since this will be the nomenclature for the foreseeable future. You may also see us refer to “Strada” (the original TypeScript codename) and “Corsa” (the codename for this effort) in internal discussions or code comments.