I could see interface,extends,declare keywords has been used in java script libraries
lib.d.ts
as we use in Java.
For example
interface HTMLObjectElement extends HTMLElement, GetSVGDocument { }
Why we can't use those keywords when we would like to apply oo design patterns to Javascript appliccations like Node.js
That is a typescript type definition file.
In order to use the same keywords you will need to code your Node.js application on Typescript and have a compiler that transform it into valid javascript.
Related
I'm using kotlin2js to generate JS library from Kotlin code. I'm then using this library in Javascript (not Kotlin). The code has some Kotlin objects and some normal classes. I can access normal classes from Javascript, but I can't access the objects in any way.
The documentation is pretty sparse, only relevant line might be this:
Kotlin preserves lazy object initialization in JavaScript.
I'm not sure what that means.
I suppose you should specify moduleName as well when accessing from javascript.
The problem was that Kotlin changed name of the method to something like this: calculate_ywek2$(). And it's very hard to figure out, because Kotlin doesn't generate Typescript definitions, so autocomplete doesn't work. The name can be changed with #JsName annotation.
I was trying to make NodeJs work with Kotlin for a HelloWorld example here.
As per the Kotlin JS documentation, #JsName annotation is required for overloaded methods. But in my experience, it is required even for a single method. Without this annotation the compiler adds a suffix to the method name as shown in the screenshot.
Is this a bug? Or am I missing something?
I'm using Kotlin 1.1.0 module provided by NPM (please check the GitHub link above for the complete codebase if required).
Kotlin compiler mangles names all functions, except for those which don't take any parameters. The motivation is: you can add overloaded function later, and this should not break binary compatibility of the code. As for #JsName: it depends on your goal. I don't know it and hence I can't tell whether you shuold put #JsName annotation on each method. If you are developing a library which is intended to be used from JavaScript, yes, you probably need to put #JsName on each function you want to be accessible from JavaScript. We are going to add another annotation which turns off mangling on entire class or file.
FlowType interface files are declared using a certain language. This page contains some examples. Where can I get an overview of the language, or an example of a lengthy interface file that demos all the available tokens/types/features?
Here's a quick overview:
declare module ModuleName {
...more declare statements
}
declare module "QuotedModuleName" {
...more declare statements
}
declare module ModuleWithDefaultExport {
// declare class exports or declare function exports also works
declare var exports: exportType;
}
declare class ClassName {
propertyName: propertyType;
methodName(arg1: argType): returnType;
}
declare function functionName(arg1: argType): returnType;
declare var varName: varType;
interface InterfaceName {
propertyName: propertyType;
methodName(arg1: argType): returnType;
}
type TypeName = someType;
The flow binary ships with some library files embedded within it. These libraries specify some pretty basic things, like core JavaScript builtins, the DOM API, Node's API, etc. You can browse those lib files on github.
The Quick Reference page in the docs is a good overview of all the language features.
The lib directory in the Flow GitHub repository contains type definitions for the JavaScript standard library, DOM, React and Node which are good starting points.
There is a large degree of overlap between TypeScript and Flow's syntax, so the DefinitelyTyped TypeScript definitions for your favorite library will give you something that will probably work in Flow with some small modifications. The biggest differences between the two for someone getting started are how you configure and run them.
declare module and declare class that you see in the example page is in TypeScript : you can learn about the language at the official site.
Basically, Typescript use a more oriented-object syntax to write your javascript applications (in the end, it will compile your code to javascript).
Regarding the examples on how to work with Flow, you could find the reference of Flow and even find examples in the Flow Github repo
I'm thinking about using TypeScript to create an online app, and this will require saving of data online.
What are my options in regards to that?
Is there anything specific to using TypeScript which makes that easier or harder?
Ideally I would use a service like Parse.com to save data, can Typescript be connected to Parse or would I have to rely upon plain JS?
TypeScript runs wherever javascript runs. So
Your options are the same as javascript.
Typescript compiles down to javascript. And it is designed to be a superset of javascript so your javascript will be valid typescript as long as you have variables declared and sometimes types mentioned.
Optional static typing + easier syntax is what makes developing in TypeScript easier.
Static typing makes refactoring and intellisense more reliable. Having an easier syntax for classes / modules means you are more likely to structure your code better.
Yes you can use parse.com with typescript
The recommended way to do that is to create a declaration file describing your javascript code. In the beginning it can be as simple as:
declare var parse:any;
I wrote some guidance on the matter here : http://basarat.github.io/TypeScriptDeepDive/#/declarations
There is a huge resource of declaration files you can find at https://github.com/borisyankov/DefinitelyTyped . In particular check out FireBase : https://www.firebase.com/ and its declaration file : https://github.com/borisyankov/DefinitelyTyped/tree/master/firebase However there isn't one on parse.com yet which is why I mentioned the way to write your own.
Additionally you don't need a declaration file if you do not want any impressive static checking of the typescript code that interacts with the parse.com's api.
I am new to Qt and currently I am doing some stuff on this topic: http://doc.qt.io/archives/qt-4.7/qtwebkit-bridge.html
What I am trying to do is:
create a JS object that maps to a C++ class with many properties and functions.
this C++ class could return any JS data types to JS environment.
this C++ class could accept any JS data types parameters from JS environment.
But I have no idea how to start, so I am wondering are there any full examples.
Check out this blogpost: http://labs.qt.nokia.com/2010/11/16/some-webkit-hybrid-stuff/
There are some explanations, and a complete example is linked.