question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider using TypeScript for 4.0

See original GitHub issue

The idea to use a transpiler (Babel) in 4.0 has been brought up numerous times (also as the idea of using coroutines). If Sequelize is going to use Babel, that would allow to use new features like classes without raising Node version requirement at the cost of an transpilation step and worse performance compared to native classes/arrow functions/etc. In my opinion that transpilation step is not worth it if it doesn’t provide any real benefit other than better BC. However, one transpiler would hugely benefit Sequelize, and that is TypeScript. Sequelize has a huge code base. Understanding it (especially for new contributors), preventing bugs (mistyped method name, types, members, params etc), and documenting all the options with JSDoc is extremely hard.

Why I think 4.0 should use TypeScript:

  • Clear declaration of class members, exports and parameter types
  • Catch errors like wrong methods, types or params at compile time
  • Awesome Autocompletion support for contributors, maintainers and users of Sequelize
  • Direct output of .d.ts files instead of third-party
  • Beautiful documentation with typedoc
  • Instead of specifying nested params in docblocks like @param {(string|Model)} options.include[].model over and over for every variation of the find() method, we could define interfaces that can be used for all the methods and documented individually. There will never be undocumented options, because to prevent a compile-time error that option has to be defined and then it will also appear in the docs.
  • Supports async/await
  • TypeScript is a superset of JavaScript. Every JS code is already valid TS code. The learning curve is very little, it’s just JS with typing on top
  • The type system is extremely flexible, even the association mixins can be modeled

What do you think?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
janmeiercommented, May 25, 2016

While I definitely see the merits of more magic documentation, and making it easier for typescript users to use sequelize, we have opted not to have a transpilation step in 4.0 - neither babel nor typescript.

The reasoning is two-fold - for one, it creates a lower barrier of entry for new developers, they don’t have to learn new syntax (I know typescript is a superset, so they could still write in plain JS, but they would still have to understand existing ts code). Secondly, we want to make it possible users to install directly from git (i.e. poiniting their package.json file directly at a specific commit) - which is not possible if we have a transpilation step.

0reactions
SimonSchickcommented, Dec 2, 2017

The main difference would be that the typings are always (or almost always) completely up to date with the sequelize implementation.

In 99% of the cases adding new types is also really trivial, I’ve not seen any recent changes (ignoring v4) that require complex typings.

I do agree that some of the current API is difficult to type, especially the magic association functions that are added on the fly, but ~95% of the sequelize API is relatively trivial to define in typescript, when in doubt you can always any that and let a contributor deal with it, worst case you have the same type safety as using JS.

It also should be noted that @types/sequelize doesn’t play well with v4 as they do not have any class definitions. https://github.com/types/sequelize/commits/master are the de-facto v4 typings (however they conflict with the typings of umzug as these depend of @types). I’ve seen numerous people trying to use @types/sequelize with v4 which lead to really confusing results at times.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.0
Consider a function in JavaScript called concat that takes two array or tuple types and concatenates them together to make a new array....
Read more >
Announcing TypeScript 4.0 - Microsoft Developer Blogs
With TypeScript 4.0, there are no major breaking changes. In fact, if you're new to the language, now is the best time to...
Read more >
Support TypeScript 4.x · Issue #1887 · kulshekhar/ts-jest · GitHub
2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0).
Read more >
5 Things I Love About TypeScript 4.0 Release - Bits and Pieces
Recently, TypeScript released the latest version of the language: V4.0. It comes with several features and enhancements available across the ...
Read more >
@typescript-eslint/parser - npm
Default undefined . This option allows you to provide one or more additional file extensions which should be considered in the TypeScript ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found