DEV Community

Discussion on: Using Typescript without compilation

Collapse
 
isaachagoel profile image
Isaac Hagoel

Which features are you referring to? Enums?

Collapse
 
fsoft72 profile image
Fabio Rotondo
  • Static typing: define variable, parameter, and return types for functions, which can help catch type-related errors during compile-time.
  • Interfaces: define the structure and type information for objects.
  • Classes and inheritance: full support for OOP, including constructors, instance and static methods, and inheritance using the extends keyword.
  • Generics: create reusable, type-safe components.
  • Enums: define a collection of related values with a friendly name
  • Namespaces: organize and group related code.
  • Decorators: a mechanism for annotating and modifying classes and class members at design time
  • Type inference: reduce the amount of type annotation required from developers.
  • Type guards and discriminated unions: perform advanced type checking and to discriminate between different types at runtime.
  • Advanced types: intersection types, union types, mapped types, conditional types, and more.
Thread Thread
 
thepassle profile image
Pascal Schilp

You can do all of these things with either JSDoc/.d.ts files, with the exception of Decorators, which are not standard in the first place (although the proposal is, finally, making some nice progress)

Thread Thread
 
fsoft72 profile image
Fabio Rotondo

You are right, but I prefer TS to write .d.ts files by itself.
I can agree with you when you say that writing JSDoc can help, but if I have to manage more external files (like .d.ts) I think that development becomes more complex: we already have to manage a lot of "external" files, like linter configuration, babel configuration, prettier configuration ... having to manually handle TWO files (js and .d.ts) for each js files I write to avoid compilation (and remembering to update the .d.ts file every time I update a method signature or type) doesn't make much sense (to me, at least) especially considering that 99% of the time, the compilation phase is transparent to the developer thanks to tools like next.js or tsc --watch.

Thread Thread
 
thepassle profile image
Pascal Schilp

but I prefer TS to write .d.ts files by itself
This is totally fine, and is a preference

I think that development becomes more complex: we already have to manage a lot of "external" files, like linter configuration, babel configuration, prettier configuration

This I disagree with, if anything, skipping typescripts compilation step/avoiding TS source code simplifies development.

Remembering to update the .d.ts file is a non-issue, because if your .d.ts file is not up to date, you'll get the tsc feedback either in your editor or terminal.

Thread Thread
 
akmjenkins profile image
Adam • Edited

The only time you absolutely 100% need feedback is in CI. Having it in your editor is a bonus, albeit one that I can’t see myself living without very easily.

Simplified development is a subjective statement.

My simplified development is having my type annotations inlined in my source code. Your simplified development is having a source code file and a separate manually maintained d.ts file and writing some of those (not all) types twice - once in the d.ts and then once in the JSDoc string

This JSDoc sounds really cool, and I now know, thanks to this article about all the capabilities of JSDoc.

If compilation was somehow a thing I wanted to avoid, I’d use this. But that’s not been my experience. The sourcemap drawback is true, but it’s a pretty minor one given all the tooling that spits this stuff out for you without requiring you to write/maintain extra stuff manually

Some comments have been hidden by the post's author - find out more