I have a few projects written on Typescript.
TS has a declaration files (d.ts) to declare non-ts libs. How it's works in Dart?
Dart looks very cool but I'd like to use Backbone and Marionette in my project.
Is there opportunity to rewrite projects at Dart or use Dart in next project using Marionette?
There are some attempts or plans to support that better but currently I guess this isn't too easy.
dart:js provides support to call between Dart and JS but this probably won't work with d.ts. You'd need to rebuild d.ts for dart:js.
Support for d.ts seems to be work in progress and a first version should become available in the not too far future https://github.com/dart-lang/sdk/issues/23423
The dev_compiler team is working on generating TypeScript output from Dart code https://github.com/dart-lang/dev_compiler/issues/397. I don't know about the status. Seems to be farther away.
You probably want to look at package:js, https://pub.dartlang.org/packages/js and see the ChartJS example there. Angular has a ts2dart compiler, but I don't know if that would actually convert the d.ts files or if you'd need to do that by hand. It doesn't seem like it would be too difficult to turn d.ts definitions into package:js definitions.
Related
Given there is a React project that uses plain javascript, is there a way to use typescript partially only to define models?
So, lets say there are a few models that map to server responses, can only those be defined in typescript while the rest of the project remains in javascript.
If its possible, how to do it?
Typescript can definitely be implemented gradually into an existing JS project, and I know a few people who have gone through the process on some monoliths, it can be a really boring process but usually low risk.
I'll link you straight away to this:
https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
The key is to understand what your goal is, and how to set everything up properly to accommodate for it, as you go it's as simple as toggling a few settings to unblock/check work as you go.
As for your question about some files being JS and some being TS, typescript handles pure JS perfectly fine, so you can switch every file to TS and even if it's pure js there won't be an issue :)
Have a read and if you need any more help on some specifics feel free to comment
I want to use ReactJS for the front end of our new system.
The back end system (in C#) has different modules which can be toggled on/off. Each module has its own set of DLLs, meaning the product can be "shipped" without unnecessary module DLLs. "You need chat functionality? Here's the DLL, drop it in your bin folder, good to go!"
Each DLL is pretty much standalone with no dependency on an other, apart from it's main parent abstraction.
I would like to know, is it possible to create something similar in a React front end? I don't want to have hundreds of react components listed with a bunch of 'if' statements to show/hide them.
I would like each module to be responsible for its own rendering & actions. Adding a brand new feature would be as easy as 'building the extra module' (not updating the 'core' system files to tell it about the extra module).
Gah, I hope that makes sense! Could anyone point me in the right direction? Is this a fools errand? Is it achievable?
Thank you in advance.
This is more question of how to split your frontend code than react specific question. Good news is, it's certainly possible. Take a look at webapack - bundling tool often use with react. I am not sure how exactly modules and DLLs work in C#, but I imagine you have some way how to include different js bundles into them. If so, webpack will help you create these bundles.
What is the best solution for including vanilla JS libraries in TypeScript projects? This is one of those things that "works" just fine, but I feel like I'm clearly not going about this in a "best-practices" sort of way.
Let's say, for example, that you want to use EaselJS in an Angular project. You can just add a link to CreateJS in your index.html file as usual, and then you have access to the global createjs object, but your compiler will of course know nothing about createjs, and will assume that you've got an error. What's the best way to let TypeScript know about this external source?
Moreso, what's the best way to enable auto-completion so that when I type "createjs." I get a list of the methods in that file? Is mixing JS and TS like this possible?
I suppose I could create a TypeScript shim that passes things through to the createjs object, but then that shim would be riddled with "errors."
Thoughts?
Thanks!
Oh, looks like this is done via a definition (.d.ts) file. There's a good tutorial here. In fact, CreateJS already has one of these available here, and if you go up a level in that Github Repo you'll find tons of these definition files in the DefinitelyTyped repository. I haven't tried this out yet, but it looks like the right direction.
You should use ambient declaration.
declare var createjs;
You use ambient declarations to tell the TypeScript compiler that some other component will supply a variable.
Basically what I want is a scaffolding tool (without bower and other stuff that it comes with) and controller, service/factory generators.
Yeoman is great but I was wondering if there's anything minimalist cli out there for angular.
Well, if all you want is a base angular app structure, that is called a boilerplate. There are a few available:
https://github.com/angular/angular-seed
https://github.com/ngbp/ngbp
https://github.com/angular-app/angular-app
However, you seem to also want a controller, service/factory generator. This will always require:
some kind of task runner (like Grunt)
or an IDE that supports templates.
Since you don't seem to like grunt (grunt IS AWESOME), these IDEs might help you...
Eclipse supports template, you can find some here
IntelliJ's PHPStorm or WebStorm have a feature called Live Templates which, IMHO, are far better than eclipse. You can find some premade templates here, but is easy to roll your own, as explained in this tutorial.
If you want a command line interface but not Yeoman's, you might want to have a look at the "Generation" section of this collection. As of today, it has one option that uses Lineman and two that made their own CLI, but they use bower. Anyway, if what you're looking for exists, it should be in there somewhere.
Will TypeScript support any of those great MV* frameworks.
I know it's too early to ask this, but what about the chances to reach support for them with this young javascript initiative?
TypeScript already supports these and every other JavaScript library. Any JavaScript code is valid TypeScript code.
Obviously to see any benefits from TypeScript these libraries would need to add type annotations, this can be done unobtrusively by creating Declaration Source Files (files with a .d.ts extension). These are basically header files that describe the type information associated with existing JavaScript code.
It is obviously outside the scope of the TypeScript project to create these Declaration Source Files for every popular JavaScript library. It is up to those projects and the community to contribute this.
You can view a sample Declaration Source File for jQuery that is included in the TypeScript samples.
DefinitelyTyped has already covered most (if not all) of mv* JavaScript frameworks.
They have definitions for angularjs, backbone, ember, knockout and more.
Check it out.
All JavaScript is TypeScript.
MV* frameworks are JavaScript.
Therefore, MV* frameworks are TypeScript.
Here is an interesting article talking about TypeScript and AngularJS
http://www.piotrwalat.net/using-typescript-with-angularjs-and-web-api/