Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript support? #56

Closed
colinshen opened this issue Jan 8, 2016 · 42 comments
Closed

Typescript support? #56

colinshen opened this issue Jan 8, 2016 · 42 comments

Comments

@colinshen
Copy link

will adonis support typescript?

@gearsdigital
Copy link

They discussed that topic recently on the adonis gitter-channel. Seems @thetutlage does not really like typescript.

screen

@colinshen
Copy link
Author

ok,i'm just curious about it. anyway, it is a good framework.

@maxime1992
Copy link

@thetutlage having typescript support is in my opinion a huge advantage.
I've been working on an Angular2 project for the last 2 months and Typescript gives another dimension to your code. Especially when it's a big project and/or if you work in team.

When you need to refactor, it's really a life saver.

So yes, at some point, typedefinitions will be needed and someone will have to make it.
But once it's done, it'll be a big step forward.

I think it might be a good idea to reconsider that issue.

Plus, people who don't want to use typescript wouldn't have to.

@RomainLanz
Copy link
Member

Creating type definition or using TypeScript to code the core of Adonis is two different things. You can still create type as a community project and use them in your code.

@thetutlage
Copy link
Member

@maxime1992 Looking at the amount of time I have, it is not possible for me to spend time in writing TS definitions. Community effort is welcomed

@maxime1992
Copy link

@thetutlage I totally understand that and my curiosity about Adonis makes me want to go deeper in the source code (if I ever find some time to).

Not sure I'll find some time for that but I'd be glad to help !
Right now, first thing first, I want to learn more about Adonis because I haven't found the time to play with it !

@rhyek
Copy link

rhyek commented Aug 27, 2017

@thetutlage I want to congratulate you and any collaborators for the amount of work that's gone into the 4.0 version. I believe this is the web framework NodeJS needed for me to be able to finally get my co-workers and myself to step away from PHP. I always thought Laravel itself was very nice, and I use it every day, and am glad you have taken inspiration from it.

So many frameworks come out for Node all the time and most of them are doing way too little or are pointlessly doing away with traditional MVC concepts which nowadays are mainstream and understood generally. None of them seem to be built on sane foundations. None of them can be taken seriously for enterprise-level project requirements.

ASP.NET MVC is my framework of choice. I love many things about it, but one of the main things is the fact that I'm working with a statically typed programming language (C#) and all the benefits that come with it. Still, ASP.NET MVC is not as easy and straightforward to work with as Laravel is.

AdonisJS has the potential to become the best of both worlds: A batteries-included, ready-to-go, easy-to-configure, get-shit-done Web framework that is also built on a more modern and sane programming language. Javascript is that language, but I do wish I could go all the way and use Typescript. The benefits of using a language like it are many and have been mentioned here and in countless other places, but to me, the single greatest benefit is that I don't have to remember hundreds of method names and their parameters, properties, return types, for the many frameworks and libraries, etc, etc, and I value this greatly because I, as a very forgetful person, need to look up documentation for the simplest things all the time and all those minutes wasted during development add up.

If I'm going to switch to Node completely, AdonisJS 4.0 will probably be the framework I pick. I'm worried that there doesn't seem to be any community effort towards writing TS definitions or anything of the sort.

I'm currently working on a small boilerplate and am manually replacing things such as const model = use('Model') to const Model = require('@adonisjs/lucid/src/Lucid/Model') and, thankfully, Visual Studio Code can provide IntelliSense for that. A blueprint that scaffolded a new project without use would be great. But then the scaffolding commands for controllers, models, etc would also need to not use use.

The blueprint could also set up a .tsconfig with a paths compiler option to alias App to the app directory and not have to use relative paths everywhere in code.

Mainly my point is I'm wondering if you still feel the same about TypeScript and if there are any new initiatives to get any of this going.

@rhyek
Copy link

rhyek commented Aug 27, 2017

Looking over some of the code, you do provide JSDoc annotations which Typescript now picks up, but I'm unsure how complete the mapping is between the two.

@thetutlage
Copy link
Member

thetutlage commented Aug 28, 2017

@rhyek

Thanks for your appraising feedback. These kind of comments gives more energy to work on AdonisJs everyday.

Regarding Typescript

I 100% agree with you that context switching between docs and code is kind of hard and eats lots of time.

I am more than happy to add support for Intellisense to the framework but it requires good amount of work. Lemme talk about it here in depth

Not a Typescript project

The project itself is not written in Typescript, that means I have to write type definitions by hand, in order to get the intellisense working

I am not sure how much help JSDOC code blocks can provide to intellisense engine

If it works out of the box without any glitches, then I am happy to improve the code blocks and make them more useable.

If not, then typedef files is the way to go.

Custom resolver

The biggest roadblock is the resolution of namespace via use and make keywords, which VScode doesn't understands at all. Which means I have to write an extension, so that it can work the same way as require.

Proxies

I make heavy use of ES6 proxies to build unified API's without writing verbose code. Also have to see if Intellisense works great with ES6 proxies or not.

Action steps.

  1. Understand how intellisense works
  2. Check the behavior of proxies.
  3. Getting everything working without the extension, which tells VScode on how to resolve modules via use method.
  4. Finally, write the extension to wire everything up.

All this requires a lot more research, since I am not a user of Vscode. I am happy to do that either, but expecting that support for Typescript will be out soon is not true.

It will be great, if someone can guide me in the right direction for

  1. Does JsDoc works seamlessly with intellisense?
  2. What is right approach to add module resolution support for the use keyword. It can be Language server or may be extensions.

@thetutlage thetutlage reopened this Aug 28, 2017
@HerringtonDarkholme
Copy link

Hi, @rhyek contacted me on gitter. I have some experience in TypeScript. So I think I can give some suggestion.

Does JsDoc works seamlessly with intellisense?

I would rather argue JsDoc cannot compete with TS completion at all. JsDoc can provide some basic completion. But anything advanced isn't available. Plus, users have to annotate their code with JsDoc to get completion.

What is right approach to add module resolution support for the use keyword.

Yes, TypeScript does provide powerful plugin architecture. One similar use case is Angular's completion. However, authoring a plugin requires much effort and great understanding of TS internal. (Indeed, Angular's plugin is developed by full time googler)


Not a Typescript project is not an excuse for not providing good definition, but highly reflective API is really good one.

e.g. https://github.com/adonisjs/docs/blob/4.0/07-lucid/01-model.adoc
Lucid define field by static method, I don't think there is any way to represent it in TypeScript.

Other features like trait, and stringly typed route e.g. Route.resource('posts', 'PostsController') do not work either.


If some one does want to write TS definition, I guess they can provide good response/request typing at best. Bad typing is the toll for highly dynamic and flexible API.

Adonis users should be conscious about this trade off.

@thetutlage
Copy link
Member

Bad typing is the toll for highly dynamic and flexible API.

I don't think so. Javascript is a dynamic language and API's built around Javascript will always make full use of it's nature.

Also Typescript is the superset, so for me having good Intellisense is important but not at the cost of spaghetti API. So things like

  1. Traits
  2. Macros
  3. Dynamic getters etc

will be there always

@rhyek
Copy link

rhyek commented Sep 8, 2017

@thetutlage I believe most of the issues with having good typing will stem from the use of the use keyword. I am not very experienced with Adonis, but the few tests I have done I find it is not needed. At least not when writing models and controllers.

I feel most of its utility can be summed up to be just a shortcut for import paths? This is not needed, IMO. Having to develop code editor plugins to support it seems to not be the best allocation of resources.

@RomainLanz
Copy link
Member

I feel most of its utility can be summed up to be just a shortcut for import paths? This is not needed, IMO.

The use function does much more that just creating a shortcut for importing module.
I let you read the documentation about the IoC, Service Provider & DI http://adonisjs.com/docs/3.2/ioc-container

@incraigulous
Copy link

For what it's worth, as a Laravel user who has been lurking on Adonis for awhile, I have to say that typescript support is the main thing I'm waiting for to take Adonis for a test drive. I feel like I will miss interfaces and proper webstorm support. I feel like typescript will help me feel more at home and provide some of the convinces I'm used to with php.

@rhyek
Copy link

rhyek commented Sep 17, 2017

@incraigulous I'm in the exact same situation. I've decided to keep using ASP.NET MVC Core for now for personal projects and Laravel at work and hope to some day revisit this framework which honestly seems quite nice, this issue aside.

@thetutlage
Copy link
Member

Board the ship and help writing it 😊

@rhyek
Copy link

rhyek commented Sep 17, 2017

I'm a totally noob, though. I'd probably do more harm than good. Hah.

@thetutlage
Copy link
Member

I don't have much time to invest right now, knowing the fact majority of users asking for intellisense never tried Adonis and are not ready to help in either way

Also there is no surity that Typescript will remain a thing, since many superset of Javascript came and went

@incraigulous
Copy link

Yeah, totally understandable @thetutlage. You've got to set your priorities as do we. Just thought you might want to be aware of something that is holding some back from giving it a chance. I think the bigger issue if the ide use function support to be honest. That is probably also the easier problem to tackle too.

You can't please everyone though and there are only so many hours in a day. Thanks for all you do! Hopefully I'll be on team Adonis one day! For now I'll probably keep lurking...

@thetutlage
Copy link
Member

I have playing a little with VsCode these days and was able to get some intellisense working without creating the language server.

What I need now is, if someone can help in creating Typedefinition files for individual repos of Adonis.

@rhyek
Copy link

rhyek commented Sep 25, 2017

I could give it a shot. Might start with Lucid. What are your ideas about the use keyword? Or where you testing with require?

@thetutlage
Copy link
Member

@rhyek Cool!

So this is how I am planning to take it on.

  1. Type definitions are required no matter.
  2. Adding support for use requires writing a language server, which I am not keen to write as of now.
  3. For now we will use /// <reference path="Route" /> comment of Typescript, which works great, I have tested it.
  4. Going forward once ES6 modules will have the Loader API finalized, I will make IoC container work with the loader over a custom use method. So that we can do import * from 'Route' and it will work.
  5. Now if Vscode works in compliance to the Loader API spec, then intellisense will work out of the box.

As said earlier, even with above points, we will always need type definitions. So it's right time to start writing them one by one.

@RomainLanz
Copy link
Member

Good news for everyone, module resolution hook has landed in Node.js! 🎉

nodejs/node@d21a11d

@RomainLanz
Copy link
Member

Closing for the moment.

Feel free to discuss it on the forum.
https://forum.adonisjs.com/

@xxzefgh
Copy link

xxzefgh commented Feb 28, 2018

I started little bit of experimenting on this, and seems like I got it working.
https://github.com/thisdotvoid/adonisjs-types
It's just a proof of concept at this moment, not sure about limitations of this approach though.

@thetutlage
Copy link
Member

@thisdotvoid

It works great. I don't see any specific downsides. But, yes will have to write all the functions in this file.

I am happy you initiated it 😄

@xxzefgh
Copy link

xxzefgh commented Mar 1, 2018

Will try to make some progress on weekends

@wilomgfx
Copy link

wilomgfx commented Apr 4, 2018

@thisdotvoid i just jumped into the adonis bandwagon and i want typescript support, ill help you out !

@xxzefgh
Copy link

xxzefgh commented Apr 4, 2018

@wilomgfx yeah, I jumped off (at least for now 😄). database support is the most important imho. this fork has done some work https://github.com/janez89/adonisjs-types

@wilomgfx
Copy link

wilomgfx commented Apr 4, 2018

@thisdotvoid perfect !

@xxzefgh
Copy link

xxzefgh commented Apr 4, 2018

Maybe we could try writing whole app in typescript, instead of just getting help from vscode? I think it's doable

@thetutlage
Copy link
Member

I don't think I will re-write the system in Typescript to make VsCode happy and then write in https://reasonml.github.io coz some other editor got crazy support for it.

I never liked the idea of TypeScript at all, Javascript is dynamic and it simply takes the freedom of having dynamic code.

I created an issue here, which shows the rough edges of Typescript microsoft/TypeScript#18656

Again, for some people these rough edges are fine, since they start thinking in Typescript way, but it's not for me

@wilomgfx
Copy link

wilomgfx commented Apr 4, 2018

@thisdotvoid na, types are the way to go!

That way type lovers like us get the types we love and @thetutlage keeps his JS codebase without type complexity which does not fit his coding type for adonis. I have contributed to many open source libs and adding TS types to @types npm package and https://github.com/DefinitelyTyped/DefinitelyTyped and thats the way to go :).

We dont actually get help from VSCode, but from the TS server. Which can be used in any code editor, ides (like WebStorm :D) to provide type hinting. Anywho, lets make the type defs really awesome to let our fellow type lovers happy :D

Side note, ill def be writing my apps in TypeScript, so i'll be (forced ;) ?) to update any type defs when adonis API and libs update, which i dont mind at all as its pretty darn simple :)

@caiusCitiriga
Copy link

Hey @thetutlage, I'd like to contribute (or at least try to) into the total rewrite if possible. Dumb question: would it be just as "simple" as taking all the files one by one and rewriting them in TS? Or am I missing something? If so, do you have any suggestions on where to start? Sounds like crazy? I really love this project just by reading the docs. It remembers me Laravel a lot. And I'd really love to see it written in ts too :)

@wilomgfx
Copy link

wilomgfx commented Apr 4, 2018

@caiusCitiriga it would indeed be turning the js into ts... but you'd have to update a fork all the time... much easier to update type defs on api changes. It also adds benefits to JS users, because typescript can help type hint js files now.

@xxzefgh
Copy link

xxzefgh commented Apr 4, 2018

@thetutlage I didn't suggest to rewrite framework itself, rather the code we write as users of framework, could be written in typescript.

In short, we could create alternative typescript starter app for cli, framework itself doesn't need to change. eg: adonis new yardstick --typescript

@wilomgfx
Copy link

wilomgfx commented Apr 4, 2018

@thisdotvoid that would definitely work, but before that we need the type definitions 100% done and working properly :)

@anurbol
Copy link

anurbol commented May 25, 2018

I've been writing in PHP for 11 years, and Laravel for few years, and loved them very much. I was also coding frontend in JS, and one day my SPA app became very complex, my brain capacity was totally exhausted and then I've opened wonderful world of TypeScript. The best part is learning took just couple of hours, and it was couple hours of pleasure. I also love so much that I can switch project from JS to TS incrementally, just changing file extension from .js to .ts and adding required type hints. After using TS in frontend, I've returned to some tasks in backend, and that was the time when I decided to say good bye to PHP world, because it looked so poor and so unmaintainable after TS experience. I started to look at node.js alternatives for Laravel, and thank god, I've found Adonis! However, the fact, that framework does not use TS is little bit disappointing, because TS is the reason, I am switching from PHP. I can still use Adonis, writing my own classes in TS, though. But if Adonis will have official support for TS, that would be perfect for so many people like me, that would be just paradise. Good to see, that work have started. I'll try to help, if I can. @thetutlage Please look at TS, you will enjoy it very much, it'll free so much brain capacity and boost your productivity, I guarantee you :) I've so much impressed by your current brain capacity/productivity and the result (Adonis), though!

@thetutlage
Copy link
Member

I started using it too https://github.com/poppinss/edge/tree/next/packages/lexer.

In version 5, most of the pieces of Adonis will be moved to Typescript and there will be an official Typescript boilerplate too.

Still couple of things to note

  1. Main priority is to make Adonis work without using any transpilers. So Typescript will be optional and not forced on users.
  2. Since IoC computes dependencies at runtime, you will have to typehint your code properly to get intellisense.

@anurbol
Copy link

anurbol commented May 25, 2018

@thetutlage That's so cool to hear! Almost like a dream :) What you've just wrote makes me 100% start migrating to Adonis. Talking about your notes:

  1. Totally agreed. I successfully use TS without any transpilers (only TS's compiler, tsc). Typescript should be always optional, I also don't use it if it does not provide much value, usually in a very simple js files.
  2. I guess this is 100% OK, since:
  • it does not bothers me much
  • writing type manually is super simple and takes 2 seconds

[Offtopic] P.S. Thank you again, wonderful framework you have made, I am hundred percent sure it will gain extreme popularity, and I've made bet for it, after analyzing dozen of frameworks (sails.js, nest.js, meteor, loopback, feathers etc.)

[Offtopic once more] Btw, it's a fun, if one read throughout posts in this issue, he can see transformation of the framework creator from "I hate TypeScript" to "I've started using it, framework will be switched to it" :D That's a good sign of open mind of the author and good future of the project

@OzairP
Copy link

OzairP commented Jun 5, 2018

@thetutlage I'd like to help out with TypeScript migration. Is there a roadmap or anywhere for discussion?

E: nevermind it's here! #871

@lock
Copy link

lock bot commented Mar 11, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests