Skip to content

Official TypeScript definitions? #81

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

Closed
BalassaMarton opened this issue Apr 14, 2015 · 69 comments
Closed

Official TypeScript definitions? #81

BalassaMarton opened this issue Apr 14, 2015 · 69 comments
Assignees

Comments

@BalassaMarton
Copy link

Are you guys planning an official Aurelia repo for the .d.ts files? I know there will be definitions in DefinitelyTyped or whatever, but the fact is, even DT contains broken or outdated definitions, and having up to date, official definitions would be very comforting.

@EisenbergEffect
Copy link
Contributor

Yes. We are working on it :)
On Apr 14, 2015 7:41 AM, "BalassaMarton" [email protected] wrote:

Are you guys planning an official Aurelia repo for the .d.ts files? I know
there will be definitions in DefinitelyTyped or whatever, but the fact is,
even DT contains broken or outdated definitions, and having up to date,
official definitions would be very comforting.


Reply to this email directly or view it on GitHub
#81.

@omidkrad
Copy link

Awesome! I also vote for the official definitions.

BTW, for modules that are written in TypeScript, you can emit definitions from them and don't have to maintain manual .d.ts files.

@cmichaelgraham
Copy link
Contributor

@omidkrad
Copy link

Hi @cmichaelgraham I read the dts generation doc it's a good start but as mentioned in the document, it only gives stong-typing for the types that can be inferred by the TypeScript compiler. But we're still missing a lot, explicit type definitions, union types, enums, etc. I'm sure Aurelia team has good reasons with going with pure ES6 code, but for me the benefits from typing outweighs the fact that the Babel compiler currently has more ES6 features implemented. I wished the decision was the other way around, i.e. using TS for source code and then transcompiling to ES6. That way you'd get both .js file and .d.ts file and in the future when there are more ES6 features supported in TS you can also use those features.

@EisenbergEffect
Copy link
Contributor

We are considering TS as an option for our main source. We can't do it now because TS doesn't support everything we need just yet. They know what we need and are working on it though.

That said, it's still a decision that needs to be made carefully. If we switch to TS that may just upset the community and ruin us. I don't know just yet. I would like to investigate further into a dual compilation strategy. My thought is that we could introduce types into the source in a way that they could be processes by Babel via Flow as well as TS at the same time. I don't know if anyone has tried that before, but it might be worth a shot.

@cmichaelgraham
Copy link
Contributor

thanks for the great input :)

independent of the above decision about aurelia source, there is tremendous value in increasing the type specificity in the ported code which will, in turn, increase the specificity of the generated type definitions.

i am working hard to try to make sure that typescript is well supported.

@omidkrad
Copy link

I like the dual compilation strategy. I was thinking maybe could use Closure Compiler Type Annotations that could be translated to TS syntax in the conversion process.

@EisenbergEffect
Copy link
Contributor

One thing is that Flow types use the same syntax as TypeScript and are already supported by Babel. So, I think that might be a better fit for us. I need to investigate a bit more. @cmichaelgraham If you are interested, this would be a related area worth looking into.

@cmichaelgraham
Copy link
Contributor

wow - its the same syntax? that is very cool. i will put it on the list for sure 👍

@EisenbergEffect
Copy link
Contributor

I think it is. It doesn't have interfaces I don't think. If we were careful, we might be able to craft our code base so that it could be compiled both by TS and Babel with Flow....and that would be pretty cool.

@EisenbergEffect
Copy link
Contributor

We could start to experiment with this on one repo first, like metadata, for example. See how it works, then go one repo at a time from there maybe.

@cmichaelgraham
Copy link
Contributor

i'm with you 100%

@omidkrad
Copy link

In their announcement they said that they will be compatible with TypeScript definitions (.d.ts files). This is great, I've just started with Aurelia but I will try to help too.

@cmichaelgraham
Copy link
Contributor

@omidkrad for reference, here is a comparison of TypeScript with Facebook Flow Type System microsoft/TypeScript#1265

@omidkrad
Copy link

I have mixed feelings about Flow, but looks like it has some more type checking and features compared to TypeScript. Stricter type checking means that code that passes Flow type checking should also pass TypeScript type checking but more features means that code that uses Flow-only features will fail if compiled as TypeScript.

@omidkrad
Copy link

OK, I see we're talking about the Babel Flow transformer. So we're not going to use Flow, just the typing syntax which is going to be the same as TypeScript (except for nullable types?).

What if the Aurelia build process did the following?

  1. Compile the source code as ES6 with Babel
  2. Copy the source code to .ts files
  3. Compile .ts source with TypeScript (tsc.exe)
  4. Deploy either the Babel or TS .js output based on some configuration setting, together with their Source Maps
  5. Deploy the TypeScript .d.ts output

If both compilation steps pass then we have a code that is compatible with the least common denominator of both languages. If anything fails then we get the appropriate error message from the respective compiler. Being able to configure which compiler output to deploy allows the developer to choose how they want to debug the code in the browser.

@EisenbergEffect
Copy link
Contributor

I think something like that is a possibility. We just haven't had the opportunity to test that out just yet...

@omidkrad
Copy link

Which ES6 features you need in Aurelia framework that are not supported in TS yet?

@EisenbergEffect
Copy link
Contributor

With 1.5, we have the language features we need. There are a few tooling issues related to cross-repo compiling and builds that I believer are lingering. @cmichaelgraham can comment on that.

@nojaf
Copy link

nojaf commented Jun 1, 2015

Any news on this?

@EisenbergEffect
Copy link
Contributor

We are planning to experiment with a hybrid compilation strategy on a couple of our small libraries, starting next week, in order to see if we can generate all the d.ts files ourselves. In the mean time, @cmichaelgraham has a repo you can use.

@delaman
Copy link

delaman commented Jun 7, 2015

I think Typescript is the way to go. I feel that using Typescript features such as 'implement/interface' will be better for making third party plugings/extensions.

Also I think enforcing the SOLID principles with Typescirpt at the Auerlia library level will promote higher QA standards for the community in general.

@Serhioromano
Copy link

Please, allow me to add my one cent for TS. I think is is said enough in @cmichaelgraham Aurelia/TS article's comments in the Aurelia blog.

It make sense to switch to TS for many reasons. And I am personally not for dual compilation strategy. This is not something that should be this flexible. I'll explain why if you allow me.

We all learn from others. We read something there and there, then we discover something on our own. If there will be 2 ways to compile Aurelia, one will become more popular and another one less. All will depends what in particular will be described in tutorials over internet.

And if at the end people will use mostly one method, another one will not worth efforts to be supported.

At the end of the day, there will be only one method left anyway.

And another reason that might sound not significant or not true, but to be 2 different method of compiling would be confusing. If I would be and new to Aurelia and just stared, then I read one article then another and in both of them different methods described I would have a question, which one is better, what are difference, ....

I understand that TS is not yet ready for Aurelia just now. But I would definitely look at TS as the ONLY way in the future.

Sorry if sound silly. If my post is unapropriate, you can delete it.

@francoishill
Copy link

I agree with you 100%. It makes sense to only support one. And since any JS
file is already a valid TS file, I would go with TS. Because typescript
only adds extra functionality to JS and does not remove anything.

On Mon, 8 Jun 2015 at 07:37 Sergey Romanov [email protected] wrote:

Please, allow me to add my one cent for TS. I think is is said enough in
@cmichaelgraham https://github.com/cmichaelgraham Aurelia/TS
http://blog.durandal.io/2015/05/06/getting-started-with-aurelia-and-typescript/
article's comments in the Aurelia blog.

It make sense to switch to TS for many reasons. And I am personally not
for dual compilation strategy. This is not something that should be this
flexible. I'll explain why if you allow me.

We all learn from others. We read something there and there, then we
discover something on our own. If there will be 2 ways to compile Aurelia,
one will become more popular and another one less. All will depends what in
particular will be described in tutorials over internet.

And if at the end people will use mostly one method, another one will not
worth efforts to be supported.

At the end of the day, there will be only one method left anyway.

And another reason that might sound not significant or not true, but to be
2 different method of compiling would be confusing. If I would be and new
to Aurelia and just stared, then I read one article then another and in
both of them different methods described I would have a question, which one
is better, what are difference, ....

I understand that TS is not yet ready for Aurelia just now. But I would
definitely look at TS as the ONLY way in the future.

Sorry if sound silly. If my post is unapropriate, you can delete it.


Reply to this email directly or view it on GitHub
#81 (comment).

@kristianmandrup
Copy link

I agree :) Time to gear up a level.

@RomainLanz
Copy link

I also agree with you.

TypeScript IS JavaScript with good sugar!

@npelletm
Copy link

npelletm commented Jun 9, 2015

I also 100% agree.

@atsu85
Copy link
Contributor

atsu85 commented Jun 21, 2015

@kristianmandrup I'm interested

@kristianmandrup
Copy link

@cmichaelgraham
Copy link
Contributor

update:

looking at route-recognizer branch as a model for each aurelia repo

created PR to fix the generated index.d.ts file's module name YoloDev/babel-dts-generator#3

here is the generated index.d.ts file:

declare module 'aurelia-route-recognizer' {
  import core from 'core-js';
  export interface RouteHandler {
    name: string;
  }
  export interface ConfigurableRoute {
    path: string;
    handler: RouteHandler;
  }
  export interface HandlerEntry {
    handler: RouteHandler;
    names: string[];
  }
  export interface RecognizedRoute {
    handler: RouteHandler;
    params: Object;
    isDynamic: boolean;
  }
  export class RouteRecognizer {
    constructor();
    add(route: ConfigurableRoute | ConfigurableRoute[]): any;
    handlersFor(name: string): HandlerEntry[];
    hasRoute(name: string): boolean;
    generate(name: string, params: Object): string;
    generateQueryString(params: Object): string;
    parseQueryString(queryString: string): Object;
    recognize(path: string): RecognizedRoute[];
  }
  class RecognizeResults {
    constructor(queryParams: Object);
  }
  export class StaticSegment {
    constructor(string: any);
    eachChar(callback: any): any;
    regex(): any;
    generate(): any;
  }
  export class DynamicSegment {
    constructor(name: any);
    eachChar(callback: any): any;
    regex(): any;
    generate(params: any, consumed: any): any;
  }
  export class StarSegment {
    constructor(name: any);
    eachChar(callback: any): any;
    regex(): any;
    generate(params: any, consumed: any): any;
  }
  export class EpsilonSegment {
    eachChar(): any;
    regex(): any;
    generate(): any;
  }
  export class State {
    constructor(charSpec: any);
    get(charSpec: any): any;
    put(charSpec: any): any;
    match(ch: any): any;
  }
}

@EisenbergEffect
Copy link
Contributor

@cmichaelgraham I'm wondering, could we remove the core-js import from the type definition file? What happens when you try to use this d.ts to code against? Any issues with or without that part?

@cmichaelgraham
Copy link
Contributor

once we have a few repos generating types, i can experiment. it seems to me that we would not need it.

@npelletm
Copy link

I really want to contribute to add TypeScript type definitions.
@cmichaelgraham : Is it possible to update/create a guide like this TypeScript generating guidance.
With this process, contributors could add types annotations on Aurelia JavaScript source code in differents aurelia repos.

Sorry for my poor english...

@cmichaelgraham
Copy link
Contributor

your english is fine 👍 once we get the pattern for parameter typing, interface declaration and usage, and basics (like declaring class members), changes to the repos for typescript typing will be the same as regular pull requests for other code changes 👍

@npelletm
Copy link

Ok I'm waiting the signal ^^

@wardbell
Copy link

@cmichaelgraham Are you thinking about generating documentation into the d.ts as well? I don't see that in your example.

I realize that most people have their eyes on the benefits of type constraints. But there is huge value in propagating some meaning into the intellisense along with syntax.

It's not hard to pass those comments along to the d.ts.

Maybe there just aren't docs in the source code?

@cmichaelgraham
Copy link
Contributor

@wardbell great call !! :) :)

ping @EisenbergEffect

shazam !! needs some formatting, but making progress...

babel-dts-generator with inline comments:

declare module 'aurelia-route-recognizer' {
  import core from 'core-js';
  export interface RouteHandler {
    name: string;
  }
  export interface ConfigurableRoute {
    path: string;
    handler: RouteHandler;
  }
  export interface HandlerEntry {
    handler: RouteHandler;
    names: string[];
  }
  export interface RecognizedRoute {
    handler: RouteHandler;
    params: Object;
    isDynamic: boolean;
  }
  export interface CharSpec {
    invalidChars?: string;
    validChars?: string;
    repeat?: boolean;
  }

  /**
   * Class that parses route patterns and matches path strings.
   *
   * @class RouteRecognizer
   * @constructor
   */
  export class RouteRecognizer {
    constructor();

    /**
       * Parse a route pattern and add it to the collection of recognized routes.
       *
       * @method add
       * @param {Object} route The route to add.
       */
    add(route: ConfigurableRoute | ConfigurableRoute[]): State;

    /**
       * Retrieve the handlers registered for the named route.
       *
       * @method handlersFor
       * @param {String} name The name of the route.
       * @return {Array} The handlers.
       */
    handlersFor(name: string): HandlerEntry[];

    /**
       * Check if this RouteRecognizer recognizes a named route.
       *
       * @method hasRoute
       * @param {String} name The name of the route.
       * @return {Boolean} True if the named route is recognized.
       */
    hasRoute(name: string): boolean;

    /**
       * Generate a path and query string from a route name and params object.
       *
       * @method generate
       * @param {String} name The name of the route.
       * @param {Object} params The route params to use when populating the pattern.
       *  Properties not required by the pattern will be appended to the query string.
       * @return {String} The generated absolute path and query string.
       */
    generate(name: string, params: Object): string;

    /**
       * Generate a query string from an object.
       *
       * @method generateQueryString
       * @param {Object} params Object containing the keys and values to be used.
       * @return {String} The generated query string, including leading '?'.
       */
    generateQueryString(params: Object): string;

    /**
       * Parse a query string.
       *
       * @method parseQueryString
       * @param {String} The query string to parse.
       * @return {Object} Object with keys and values mapped from the query string.
       */
    parseQueryString(queryString: string): Object;

    /**
       * Match a path string against registered route patterns.
       *
       * @method recognize
       * @param {String} path The path to attempt to match.
       * @return {Array} Array of objects containing `handler`, `params`, and
       *  `isDynanic` values for the matched route(s), or undefined if no match
       *  was found.
       */
    recognize(path: string): RecognizedRoute[];
  }
  class RecognizeResults {
    constructor(queryParams: Object);
  }

  //  A Segment represents a segment in the original route description.
  //  Each Segment type provides an `eachChar` and `regex` method.
  // 
  //  The `eachChar` method invokes the callback with one or more character
  //  specifications. A character specification consumes one or more input
  //  characters.
  // 
  //  The `regex` method returns a regex fragment for the segment. If the
  //  segment is a dynamic or star segment, the regex fragment also includes
  //  a capture.
  // 
  //  A character specification contains:
  // 
  //  * `validChars`: a String with a list of all valid characters, or
  //  * `invalidChars`: a String with a list of all invalid characters
  //  * `repeat`: true if the character specification can repeat
  export class StaticSegment {
    constructor(string: string);
    eachChar(callback: (spec: CharSpec) => void): any;
    regex(): string;
    generate(params: Object, consumed: Object): string;
  }
  export class DynamicSegment {
    constructor(name: string);
    eachChar(callback: (spec: CharSpec) => void): any;
    regex(): string;
    generate(params: Object, consumed: Object): string;
  }
  export class StarSegment {
    constructor(name: string);
    eachChar(callback: (spec: CharSpec) => void): any;
    regex(): string;
    generate(params: Object, consumed: Object): string;
  }
  export class EpsilonSegment {
    eachChar(callback: (spec: CharSpec) => void): any;
    regex(): string;
    generate(params: Object, consumed: Object): string;
  }

  //  A State has a character specification and (`charSpec`) and a list of possible
  //  subsequent states (`nextStates`).
  // 
  //  If a State is an accepting state, it will also have several additional
  //  properties:
  // 
  //  * `regex`: A regular expression that is used to extract parameters from paths
  //    that reached this accepting state.
  //  * `handlers`: Information on how to convert the list of captures into calls
  //    to registered handlers with the specified parameters.
  //  * `types`: How many static, dynamic, or star segments in this route. Used to
  //    decide which route to use if multiple registered routes match a path.
  // 
  //  Currently, State is implemented naively by looping over `nextStates` and
  //  comparing a character specification against a character. A more efficient
  //  implementation would use a hash of keys pointing at one or more next states.
  export class State {
    constructor(charSpec: CharSpec);
    get(charSpec: CharSpec): State;
    put(charSpec: CharSpec): State;

    //  Find a list of child states matching the next character
    match(ch: string): State[];
  }
}

@cmichaelgraham
Copy link
Contributor

@npelletm
Copy link

Yes great job cmichaelgraham :),
With documented typescript definition files development will be easiest.
Give us the signal when it will be ready for aurelia-repos :)

@nojaf
Copy link

nojaf commented Jun 26, 2015

Yeah really light the beacons when this is ready. Can't wait.

https://youtu.be/sIhnYFRu4ao?t=2m

@RomainLanz
Copy link

Nice one!

Thanks @cmichaelgraham

@wardbell
Copy link

"Shazam!!" indeed! Well played, sir.

@laurentiustamate94
Copy link

Any news on this?

@EisenbergEffect
Copy link
Contributor

We've had official d.ts files for a while now. When you jspm install or bower install an Aurelia library you automatically get them. They are part of every release and always up to date with the source. We have a new validation process we are putting in place right now which will ensure that they are more accurate going forward. New releases coming in the next day or two.

@cmichaelgraham
Copy link
Contributor

they even have code comments in them 👍

@laurentiustamate94
Copy link

Sounds great, I thought that there were still news as the issue wasn't closed 👍

@ryanwischkaemper
Copy link

@cmichaelgraham The d.ts files keep getting better and better, but I have to set up a gulp task to copy them to my typings folder (to keep project organized, among other things). Do you plan on publishing them to TSD?

@EisenbergEffect
Copy link
Contributor

Can't you set up your project's tsconfig file to simply look inside jspm_packages?

@ryanwischkaemper
Copy link

@EisenbergEffect I could, but sometimes there are other .d.ts files within jspm_packages subdirectories that I don't want included. I've also had instances where, during an Aurelia version upgrade, folders of older versions were left behind which resulted in a handful duplicate .d.ts files. It's not a huge deal, because I needed to clean out those old folders anyway, but it would ease development for lots of us if we could use the defacto typescript definition file package manager.

That being said, I assumed publishing to TSD could be incorporated into your build tasks, but I double checked and apparently that's not yet possible

@MihaMarkic
Copy link

Same here. If I include jspm_packages all hell breaks loose - a ton of T2300 (duplicate identifier) are reported.
It'd be nice to have the definitions in TSD repository so to include only relevant ones.

@EisenbergEffect
Copy link
Contributor

Please have a look at our TypeScript skeleton to see how to configure things properly.

@MihaMarkic
Copy link

You mean the Typescript Kit from Getting started?

@EisenbergEffect
Copy link
Contributor

No, I mean the official TypeScript navigation skeleton. It can be found here: https://github.com/aurelia/skeleton-navigation-typescript But we will be moving all the skele variations into a single repo soon.

@MihaMarkic
Copy link

Aaaah, there are samples floating around, easy to get confused. Looks promising, will dig into, thanks.

@masaeedu
Copy link

@EisenbergEffect That link 404s now. Where do the skeletons live at the moment?

@plwalters
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests