TypeScript vs Zig
When comparing TypeScript vs Zig, the Slant community recommends Zig for most people. In the question“What are the best (productivity-enhancing, well-designed, and concise, rather than just popular or time-tested) programming languages?” Zig is ranked 18th while TypeScript is ranked 23rd. The most important reason people chose Zig is:
It's safer than C, at least.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Optional static typing
Typescript has optional static typing with support for interfaces and generics, and intelligent type inference.
It makes refactoring large codebases a breeze, and provides many more safeguards for creating stable code.
Pro Strong typed language
Lot of benefits of it, you can read this.
Pro Strict superset of Javascript
Every existing Javascript program is already a valid TypeScript program giving it the best support for existing libraries, which is particularly useful if you need to integrate with an existing Javascript code base.
Pro First party Visual Studio support
As a Microsoft developed project, it has first party Visual Studio support that's on par with its C# support with features like syntax sensitive statement completion.
Pro Has a repository of high quality TypeScript type definitions for popular libraries
There are many ready to use and high quality TypeScript definitions for popular libraries including jquery, angular, bootstrap, d3, lodash and many-many more.
Pro Adds support for object-oriented programming
Typescript enables familiar object-oriented programming patterns: classes, inheritance, public/private methods and properties, et cetera.
Pro Polyfill for ES6 fat-arrow syntax
Typescript implements the fat arrow syntax, which always maintains the current context for this
and is a shorter/more convenient syntax than traditional function definition.
Pro Great support for React, integrated typed JSX parsing
Strongly typed react components, so UI "templating" automatically gains type safety.
Pro Great support for editors (Sublime, Code, Vim, IntelliJ...)
Pro Works well with existing Javascript code
Both can call Javascript code and be called by Javascript code. Making transitioning to the language very easy.
Pro Compiles to very native looking code
Compiles to simple looking Javascript making it easy to understand what is happening and learn the language (if you already know Javascript).
Pro Built and supported by Microsoft
Being built by Microsoft, TypeScript is much more likely than most other similar open-source projects to receive continued long-term support, good documentation, and a steady stream of development.
Pro Ability to do functional programming
Pro Clear roadmap
TypeScript has a clear and defined roadmap with rapid and constant releases.
Pro Low number of logical errors brought in by built-in type annotations
TypeScript's built-in type signatures allow developers to fully document interfaces and make sure that they will be correctly compiled. Therefore, cutting down on logical errors.
Pro Works well with Angular 2
Angular 2 is built using TypeScript and applications built using it can make use of that (or not).
Pro Some safety
It's safer than C, at least.
Pro C Interop
Zig programs can import C libraries and export header files to be used in C programs.
Pro Performance
Zig is pretty fast, in some cases even faster than C.
Pro Control flow is simple and obvious
No operator overloading, property methods, runtime dispatch, macros, etc.
Pro Cross-compilation is easy
The Zig compiler can build artifacts for any Tier 3 Supported platform without additional downloads.
Pro Small binary
Produces binary smaller than C.
Pro Compile-time execution
Zig can execute code at compile-time, allowing for more performant and readable programs.
Pro No Hidden Control flow
Zig will not do anything on your back that might slow down your program & make you loose your control over your program.
Cons
Con Too similar to Javascript
Presents some advantages compared to Javascript, but because it is designed to be a superset of Javascript, it means all the bad parts of Javascript are still present.
Con Type checking not enforced by default
You have to use compiler flags to make sure it catches flaws like usage of implicit any, etc.
Con Type inference coverage is incomplete
The default type when declaring and using a variable is any
. For example, the following should break but does not:
function add(a:number) { return a + 1 }
function addAB(a, b) {return add(a) + b}
addAB("this should break but doesn't :(", 100)
In order to avoid this, you have to declare type signatures for every variable or parameter or set the flag --noImplicityAny
when running the compiler.
Con Requires "this" for field access
Even in cases were there is no ambiguity, you still have to use "this.fieldName" instead of just "fieldName".
Con Syntax is too verbose
Con No support for dead code elimination
Typescript compiler does not remove dead code from generated file(s), you have to use external tools to remove unused code after compilation. This is harder to achieve, because Typescript compiler eliminated all type information.
Con No support for conditional compilation
There is no clean way to have debug and release builds compiled from the same source, where the release version removes all debugging tools and outputs from the generated file(s).
Con Awful error messages
Comparing to Elm or Rust for example, TypeScript's error messages won't say you very much. For example if you change method of interface which your class implements it won't say your class have incorrect implementation. Instead it'll show error in usage of instances of class. In some cases it can spoil hours of your work trying to figure out why your parameters are incorrect.
Con Technical debt
As consequence of not enforcing type checking.
Con No Java-like package structure
If you prefer a Java-like approach of partitioning your code into different packages, the module system of typescript will confuse you.
Con Small community
Con No option to declare that a function throws errors
Con Convoluted syntax
Claims to be an improvement over C, but in this area, not really.
Con No lambdas
Missing many key and useful features other languages have.
Con Deceptively gives impression it's near being production ready
No plans to hit 1.0 until 2025 (3 years later), according to Zig Roadmap speech. Impression is given that (0.9.1) language was close to ready, when it's not.
Con Creator admits to not knowing what he's doing
Creator admits his shortcomings during Zig Roadmap speech. Very disturbing. Not a language to invest in or take seriously, outside personal experimentation.
Con No closures
Does not have closures.
Con Almost no community
Lacking in libraries and users.
Con No interfaces/traits
Features that are useful are missing, where you can find them in other languages.
Con Fundraising looks suspicious
Why do we keep seeing an overhyped unfinished alpha level language showing up everywhere? That answer looks like a financial incentive to promote the language, the Zig Software Foundation, that is making hundreds of thousands of dollars a year from donations. To aggressively maintain cash flow, it appears any opinions that goes against their narrative is suppressed, attacked, or eliminated. All while the hype machine runs rampant. That isn't a language for the people, that looks to be a cash grab for the few that will result in nothing useful. Save yourself the headache and games, better to just use C or other languages with C-like syntax, can interface with C, and are actually useful. Better to not waste your valuable time on crap like Zig, false media hype, or getting scammed.
”If it sounds too good to be true, it probably is.”
This blog has published 2 excellent articles on how Zig's claims do not live up to reality after more than 6 years of development.
Con Poor compiler errors
Several years into development, language still a mess, and no hope of fixing itself for yet more years later.
Con No standard package manager
Several years into development, and still no standard package manager is ridiculous.
Con Exhibits cult-like behavior and animosity towards other programming languages
Strange culture that bashes other languages and are not open to criticism about the faults of their language. Very close-minded, sometimes scary.