jamesshore / quixote

CSS unit and integration testing
Other
847 stars 45 forks source link

Add support for Typescript language #16

Closed greybax closed 7 years ago

greybax commented 9 years ago

I think it would be good to add support for typescript, for using this library in TS syntax. It will be helpful for TypeScript developers

greybax commented 9 years ago

sent PR https://github.com/jamesshore/quixote/pull/15

jamesshore commented 9 years ago

Thanks for the pull request. I'm in favor of this in principle. I'm not ready to make it part of our release until we have:

I don't plan on working on this myself, but I'd be happy to accept quality contributions from the community.

jamesshore commented 9 years ago

Perhaps the Typescript could be automatically generated from the source code. There's already dynamic type checking built into every API call and that could be used to generate the Typescript.

For example, QElement.getRawStyle() looks like this :

Me.prototype.getRawStyle = function getRawStyle(styleName) {
    ensure.signature(arguments, [ String ]);

    //...
};

That ensure.signature() call checks that the function is called with exactly one parameter, which must be a string. A call like that is (or should be) is the first line of every API function. I'd be willing to tweak those calls to better work with a .ts code generator.

greybax commented 8 years ago

.d.ts files needed just for declaring syntax for using JS library code in TypeScript. So it means, that we shouldn't re-write JS library to the same TypeScript library. PR #15 is just to extend quixote library to guys which developed their code on TypeScript. In this case for using quixote library in TypeScript code just to add quixote.js and quixote.d.ts file which has the same version. Also works on DefinitivelyTyped. For tests just added test framework, library.js code and library.d.ts defunitions

jamesshore commented 8 years ago

@greybax Please see https://github.com/jamesshore/quixote/issues/16#issuecomment-143327985.

moefinley commented 8 years ago

I second the use of DefinitelyTyped, alongside the Typings project it is the easiest why to manage definition files within your own projects.

I'm not sure of a way to test the definition file's validity other than converting the Quixote project to Typescript allowing you to automatically generate the definition file when it is compiled.

However IMHO even if the definition file is manually curated and has some flaws it's better than nothing. The definitelyTyped community is still fixing issues with the JQuery definitions.

iam3yal commented 8 years ago

@jamesshore

a way to automatically test that the .ts files are correct

You don't need to rewrite Quixote in TypeScript or use .ts files at all but just adding definition files will do and these can't possibly be validated through automation because that would be as if a compiler of a statically typed language warned you that you use the wrong types before it has enough information to infer that or your testing tools told you that you're writing the wrong tests.

However, I really don't think that definition files really need to be part of the project itself, there are central repositories like DefinitelyTyped and now NPM through Typings where people can upload it independently from the project.

@moefinley

I'm not sure of a way to test the definition file's validity other than converting the Quixote project to Typescript allowing you to automatically generate the definition file when it is compiled.

Yeah, writing in TypeScript helps to generate the definition files but still this isn't really helps in terms of validation because you can still specify the wrong types in TypeScript and make mistakes, however, it can help to keep the definition files in sync with the library.

The kind of tests that you can find at the DefinitelyTyped repo is basically tests that don't contain assertions but just calls to the APIs of the library and because the *.d.ts file is referenced to the test file, the compiler will throw errors if values are of incorrect types but yeah, as I pointed above there's no really a way to validate the definition file itself.

jamesshore commented 7 years ago

Closing this issue due to lack of activity.

jamesshore commented 7 years ago

Removing 'wontfix' tag. I'm not opposed to this, just not interested in implementing it myself.