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 #381

Closed
hongbo-miao opened this issue Aug 7, 2016 · 103 comments · Fixed by feathersjs-ecosystem/feathers-hooks#135 or feathersjs-ecosystem/socketio#60
Closed

TypeScript support #381

hongbo-miao opened this issue Aug 7, 2016 · 103 comments · Fixed by feathersjs-ecosystem/feathers-hooks#135 or feathersjs-ecosystem/socketio#60

Comments

@hongbo-miao
Copy link

hongbo-miao commented Aug 7, 2016

IMPORTANT: Feathers 4 and later has built-in TypeScript support. Please see the docs for more information

http://docs.feathersjs.com/frameworks/angular2.html
Now the demo uses

const feathers = require('feathers/client');
const socketio = require('feathers-socketio/client');
const io = require('socket.io-client');
const localstorage = require('feathers-localstorage');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest/client');
const authentication = require('feathers-authentication/client');

Please support TypeScript definitions to use import!

@hongbo-miao
Copy link
Author

Oh, just saw #64... But maybe leave this open? So some people will offer help?

@daffl
Copy link
Member

daffl commented Aug 7, 2016

The best way to move this forward would be to start a repository with some basic Typescript definitions (in #64 I posted some pointers on where to start) and continue
discussion there.

I can leave this issue open for another month or two but the other issue was open for almost a year with nobody picking it up. As mentioned there, the current core team is not using Typescript or Angular so it isn't really on our radar (and we'd prefer only keeping issues open if there is a chance that they'll be addressed in the foreseeable future).

@daffl
Copy link
Member

daffl commented Sep 2, 2016

I think @Harangue has been working on some basic definitions. Maybe we can move the discussion we had on Slack about where they would live over here?

@hongbo-miao
Copy link
Author

hongbo-miao commented Sep 2, 2016

sure! If need close this issue, just go ahead.

@rollymaduk
Copy link

It will be really nice if typescript can be supported.. how can I help?

@jack-guy
Copy link

@rollymaduk I've made some decent progress on definitions for Feathers, but we have yet to establish the best way to distribute them (and things are a little transitional with TypeScript 2 about to release). If you'd like to have something to work off until then, you can see this gist I've worked on.

@rollymaduk
Copy link

@Harangue really nice work infact it looks quite ready.. I guess some areas that may require some attention would be incorporating some basic plugins like authentication, providers (rest,socke.io,primus) and some of the db adapters right? please what do you mean by the best way to distribute them?

@daffl
Copy link
Member

daffl commented Sep 16, 2016

I'm not sure if we discussed this yet, but I think it'll be fine if we distribute the Typescript definitions in the main repository as long as there is someone to maintain and keep them up to date. So once they are ready, we can make it part of a Feathers 2.1 release (which I think might also ship with some warnings that e.g. callbacks in services will be deprecated in v3).

@j2L4e
Copy link
Contributor

j2L4e commented Oct 5, 2016

Is there any fork of generator-feathers for TypeScript? @Harangue How are you generating your TS projects? Interested in working on a TS fork of the generator?

edit: I forked the generator and pushed a first commit. https://github.com/j2L4e/generator-feathers-ts.

@daffl
Copy link
Member

daffl commented Nov 8, 2016

So @Harangue has pretty much implemented a large set of the Feathers Typescript definitions already in https://gist.github.com/harangue/9d4ed79118e2656f5e3d2d699296ed36 we just need someone to review and potentially finalize them and submit them into the TypeScript definitions repository.

I am going to make this part of the Auk release which will land before the end of the year. If nobody steps up until then this issue will be closed for good and there will be no official TypeScript support or further discussion about this other than a pull request for the whole thing.

@ghost
Copy link

ghost commented Nov 8, 2016

If their quality is good you should consider bundling the definitions with Feathers. I think a lot of people would want to avoid using a secondary package manager as much as possible.

@j2L4e
Copy link
Contributor

j2L4e commented Nov 8, 2016

They'd be installable via npm i @types/feathers. You don't need stuff like typings any longer.

@daffl
Copy link
Member

daffl commented Nov 9, 2016

I thought you just add them to https://github.com/DefinitelyTyped/DefinitelyTyped. Whatever is the normal way of doing this. If we add them to the core repo the other plugin repositories probably need definitions added accordingly.

@j2L4e
Copy link
Contributor

j2L4e commented Nov 9, 2016

From the DefinitelyTyped FAQ:

The types-2.0 branch is automatically published to the @types scope on NPM thanks to types-publisher. This usually happens within an hour of changes being merged.

Didn't know that. So adding them to DefinitelyTyped would suffice.

@ghost
Copy link

ghost commented Nov 9, 2016

Ah, JS. You're gone for a month or two and the ecosystem evolves 😄

@jack-guy
Copy link

Sorry that there's been radio silence about this on my end for so long. I just released another revision of the gist today that fixes some issue I'd had with the old typings. I'm finally able to start working with Feathers again on one of my projects, and I expect to be adding typings at the very least for the modules I find myself using.

The definition as it exists in the gist is ready to be submitted to Definitely Typed except for 1) typings tests (just need to pull some examples from the Feathers docs) and 2) JS Doc annotations (which would be nice for intellisense, but are not essential).

Technically the hook typings should be extracted to feathers-hooks as well. Extending typings here gets a little messy however, as uberproto has some mixin patterns that are a little challenging to replicate with static types.

@daffl
Copy link
Member

daffl commented Nov 17, 2016

Good to have you back @Harangue. I think we can leave the hook typings in here for now since we are planning to make hooks part of core (see #408). Also the typings might need to be updated with the new .hooks method as described in https://blog.feathersjs.com/feathers-application-and-error-hooks-7a5982e70024 (not yet documented, working on it :).

@stevehipwell
Copy link

@Harangue when do you think you will be submitting your types to definitely typed?

@subvertallchris
Copy link

Hey everyone, really cool to see TypeScript defs coming along. @Harangue, what's your recommendation for importing feathers in conjunction with the defs in your gist? They aren't exporting namespaces that match the feathers libraries, so import ... from 'feathers' throws an error.

@jack-guy
Copy link

Hey @subvertallchris, you can use

import * as feathers from 'feathers';`

or

import feathers = require('feathers');

they're equivalent. :) Just when I thought I was getting time for Feathers again I got caught up in other stuff, but I'm hoping to have these definitions fleshed out completely by the new year.

@georgeedwards
Copy link

@j2L4e Your TS generator fork seems to be 404'ing ? Any news on this? Also, @Harangue how are you getting on? I am really keen to see this land and am happy to help the implementation of TS definition files, a fork with a feathers generate --ts flag to make the cli play with typescript nicely or docs. Let me know.

@j2L4e
Copy link
Contributor

j2L4e commented Dec 19, 2016 via email

@Chrisdf
Copy link

Chrisdf commented Jan 17, 2017

Is there anyone still working on this issue? I would very much like to use this project with Typescript

@daffl
Copy link
Member

daffl commented Nov 17, 2017

For the next version, @j2L4e has been doing some great work on polishing the typings. Here are the steps to try it out and beta test:

npm i -g lerna
git clone -b buzzard-j2L4e  https://github.com/feathersjs-ecosystem/feathers-typescript.git
cd feathers-typescript
lerna bootstrap

lerna will link all the packages and deps for you. Now go to the ./packages/tests subfolder (where no tests can be found yet, so i made it a kind of playground) and try out the TS goodness! Check out index.ts.

To compile and run, run npm start from ./packages/tests

@erikmav
Copy link

erikmav commented Jan 9, 2018

Just started migration from Feathers 2 to 3, index.d.ts files are now missing from the head @feathersjs packages. Any plans to restore them?

@daffl
Copy link
Member

daffl commented Jan 9, 2018

As mentioned one comment above, they have been moved to https://github.com/feathersjs-ecosystem/feathers-typescript/tree/buzzard-j2L4e to be submitted to DefinitelyTyped. @j2L4e is too busy right now so it is up to somebody else to pick this up. From what I understood it is mostly getting the Linting passing and submitting them to DefinitelyTyped. I'll happily help whoever is willing to pick this up but have no plans to take it on myself.

@j2L4e
Copy link
Contributor

j2L4e commented Jan 9, 2018

Yep, it was a lot more work than i had anticipated and feedback from the community was virtually zero. I will make it happen as soon as i find the time. Not too soon, though.

@j2L4e
Copy link
Contributor

j2L4e commented Jan 9, 2018

if anyone would chime in here, it would be really really awesome. It's all about the DT linting now, that aside everythings working fine-ish

a quick copy and paste from slack:

guys, I'm really really busy at the moment, so the typings are anything but top priority. they do work but DefinitelyTyped is quite strict in terms of linting rules. if you could help with making the typings pass the definitelytyped linting process, that would be awesome

check out my DT fork here https://github.com/j2L4e/definitelytyped, you'll find the feathersjs packages in types/feathersjs__packagename

clone, npm install and run the linter on one of the packages, e.g. npm run lint @feathersjs/feathers (edited)

@feathersjs/feathers is already linting properly, so you can use it as a reference. (edited)

@daffl
Copy link
Member

daffl commented Jan 11, 2018

TypeScript definitions are waiting for review to be added to DefinitelyTyped at DefinitelyTyped/DefinitelyTyped#22805

@poupryc
Copy link
Contributor

poupryc commented Jan 18, 2018

Definitions are now accessible via NPM !

@j2L4e
Copy link
Contributor

j2L4e commented Jan 18, 2018

Yep, install @types/feathersjs__package for package @feathersjs/package and provide some feedback please!

@Erikma thanks for your support!

@poupryc
Copy link
Contributor

poupryc commented Jan 18, 2018

@j2L4e Thank you for your work! But are you sure you have exported all @featherjs/express functions? I can't find any mention of rest, json, notFound and urlencoded in your typescript definitions file.

image

@j2L4e
Copy link
Contributor

j2L4e commented Jan 19, 2018

you're right, those are missing.

add a typings.d.ts file for now with:

import { ErrorRequestHandler, RequestHandler } from 'express';

declare module '@feathersjs/express' {
    export function errorHandler(options?: any): ErrorRequestHandler;
    export function notFound(): RequestHandler;
    export const rest: {
        (): () => void;
        formatter: RequestHandler;
    };
}

no idea where urlencoded should go.

@daffl
Copy link
Member

daffl commented Jan 19, 2018

urlencoded and json have been added to express in the last minor version. Have the express typings not been updated yet?

@j2L4e
Copy link
Contributor

j2L4e commented Jan 19, 2018

Is that express or feathersjs/express?

@j2L4e
Copy link
Contributor

j2L4e commented Jan 19, 2018

So you should be able to do Import { urlencoded, json } from '@feathersjs/express'? Or would you get it from the exported original?

@daffl
Copy link
Member

daffl commented Jan 19, 2018

Everything that's exported from require('express') is re-exported by @feathersjs/express: https://github.com/feathersjs/express/blob/master/lib/index.js#L82

@poupryc
Copy link
Contributor

poupryc commented Jan 19, 2018

image
Also, do you know how to deal with channels.ts with definitions that are fine?
I'm sorry to throw all the problems at you in such a short time.

@j2L4e
Copy link
Contributor

j2L4e commented Jan 20, 2018

Import @types/feathersjs__socket-commons

@poupryc
Copy link
Contributor

poupryc commented Jan 21, 2018

Import ? I do not understand

@j2L4e
Copy link
Contributor

j2L4e commented Jan 21, 2018 via email

@jakobrosenberg
Copy link

If I install @types/feathersjs__feathers my app.channel doesn't work. If I then add @types/feathersjs__socket-commons my app.on stops working.

@j2L4e
Copy link
Contributor

j2L4e commented Jan 25, 2018

will be fixed via DefinitelyTyped/DefinitelyTyped#23195

please take any further issues over here: https://github.com/feathersjs-ecosystem/feathers-typescript/issues

@corydeppen
Copy link

Issue tracking for TS definitions is a bit confusing. You're directing folks to the feathers-typescript repo but you mentioned "This repo is now obsolete". If you're not going to maintain the definitions in the respective repos and instead utilize DT, I think it'd make most sense to keep the issues in the DT repo as well, since that's presumably where the PRs will originate and be merged.

@j2L4e
Copy link
Contributor

j2L4e commented Jan 25, 2018

I think we than decided to give it a try here. I've been getting requests through several channels, and directing people to go over there Was a quick way to centralize that. Personally, i dont really care where it goes as long as it's one place

@jakobrosenberg
Copy link

Is there any reason we can't use feathers.services.dogs instead of feathers.service('dogs')?

@daffl
Copy link
Member

daffl commented Jan 26, 2018

Yes. feathers.service('dogs') calls defaultService (which instantiates service on the client) and removes slashes from service names.

@daffl
Copy link
Member

daffl commented Jan 26, 2018

TypeScript definitions are now in DefinitelyTyped.

Please direct any issues and questions to https://github.com/feathersjs-ecosystem/feathers-typescript/issues

@daffl daffl closed this as completed Jan 26, 2018
@feathersjs feathersjs locked as resolved and limited conversation to collaborators Jan 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet