ember-simple-auth icon indicating copy to clipboard operation
ember-simple-auth copied to clipboard

TypeScript definitions for injected session service

Open allthesignals opened this issue 5 years ago • 11 comments

I'm trying to import this service:

import EmberSimpleAuthSession from 'ember-simple-auth/addon/services/session';

So that I can use it as a type:

export default class ShowProjectController extends Controller {
  @service
  session!: EmberSimpleAuthSession

...according to the e-typescript documentation.

But TypeScript can't find the definitions. So, I was able to pull this in and have better luck: https://github.com/Gavant/octane-bootcamp/blob/master/types/ember-simple-auth/services/session.d.ts

But, I'd hate for this file to fall out of sync to any changes across versions.

Separately, I know there's some churn on how to deal with Mixins, but we can at least type parts of the addon. Is there something I'm missing?

allthesignals avatar Dec 16 '19 22:12 allthesignals

It's been a year on this issue. Any updates here?

RobbieTheWagner avatar Dec 17 '20 18:12 RobbieTheWagner

just so you guys now, this is still an up-to-date issue in 2021 :)

yavuzitconsulting avatar Mar 18 '21 18:03 yavuzitconsulting

I'd be interesting in contributing type definitions for ESA if there is interest from the maintainers.

@marcoow @BobrImperator Any opinions on how best to add type definitions?

An index.d.ts file would be the most straightforward to add but might end up being difficult to maintain. Since there is already extensive JSDoc we could look at generating type definitions from the JSDoc comments, but this will require some new CI tooling to make sure the JSDoc types are correct. I also have concerns that the base class implementations often don't match the JSDoc comments (since the JSDoc represents how subclasses should implemented, rather than representing the implementations of the base classes). Fixing that particular issue may require a decent amount of code changes to the base class implementations.

steveszc avatar Sep 27 '21 15:09 steveszc

There is also the possibility of full typescript conversion of the addon, although I'm not sure if there would be interest in that from the maintainers.

steveszc avatar Sep 27 '21 15:09 steveszc

2023, still an open issue, anyone have the solution yet?

yavuzitconsulting avatar Feb 08 '23 14:02 yavuzitconsulting

@marcoow any plans to add types?

RobbieTheWagner avatar Feb 08 '23 15:02 RobbieTheWagner

I don't think anyone on our side is currently planning to do this tbh but we'd be happy to merge a PR!

marcoow avatar Feb 08 '23 15:02 marcoow

Perhaps someone could PR in the Gavant types linked above?

RobbieTheWagner avatar Feb 08 '23 15:02 RobbieTheWagner

I have a much more robust set of types we've been using internally at CrowdStrike. I'll see if I can get those PR'd as an index.d.ts

steveszc avatar Feb 08 '23 15:02 steveszc

PR open, feedback welcome 😃 https://github.com/mainmatter/ember-simple-auth/pull/2514

steveszc avatar Feb 08 '23 16:02 steveszc

Thanks for pinging the issue 👍 I've been looking into refactoring the codebase to use tracked and native classes. I think it could be possible to use typescript at that point or at least do some groundwork into making it easier to type.

BobrImperator avatar Feb 08 '23 17:02 BobrImperator