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

getOwner(this) returns unknown type #1471

Closed
1 of 21 tasks
mydea opened this issue Jan 25, 2022 · 4 comments
Closed
1 of 21 tasks

getOwner(this) returns unknown type #1471

mydea opened this issue Jan 25, 2022 · 4 comments
Labels
bug:working-as-intended Not a bug. This is the intended behavior types:core Something is wrong with the Ember type definitions

Comments

@mydea
Copy link
Contributor

mydea commented Jan 25, 2022

Which package(s) does this problem pertain to?

  • @types/ember
  • @types/ember__string
  • @types/ember__polyfills
  • @types/ember__object
  • @types/ember__utils
  • @types/ember__array
  • @types/ember__engine
  • @types/ember__debug
  • @types/ember__runloop
  • @types/ember__error
  • @types/ember__controller
  • @types/ember__component
  • @types/ember__routing
  • @types/ember__application
  • @types/ember__test
  • @types/ember__test-helpers
  • @types/ember__service
  • @types/ember-data
  • @types/rsvp
  • Other
  • I don't know

In v4 of the types, getOwner(this) returns an unknown type. As far as I can tell that is not really correct, it should either return some type of Owner or just an ApplicationInstance or something along this line?

@chriskrycho
Copy link
Member

Thanks for the report! The problem is that Ember’s actual public API here is underspecified. See discussion at emberjs/ember.js#19916. Once we have that resolved, we’ll update these types accordingly!

@chriskrycho
Copy link
Member

Documenting a workaround here while I work on trying to get emberjs/ember.js#19916 unblocked: you can write a module extension like this in your types locally:

declare module '@ember/application' {
  interface Owner { 
    lookup(fullName: string, options?: LookupOptions): T | undefined; 
    factoryFor(fullName: string, options?: LookupOptions): Factory<unknown, unknown> | undefined; 
    factoryFor(fullName: string, options?: LookupOptions): Factory<unknown, unknown> | undefined; 
    buildChildEngineInstance(name: string, options?: EngineInstanceOptions): EngineInstance; 
    register(fullName: string, factory: Factory<T, C>, options?: object): void; 
    hasRegistration(name: string, options?: LookupOptions): boolean; 
    mountPoint?: string; 
    routable?: boolean; 
  } 

  export function getOwner(object: unknown): Owner;
}

(This is basically a safer version of the types over in Ember.)

@chriskrycho chriskrycho added types:core Something is wrong with the Ember type definitions bug:working-as-intended Not a bug. This is the intended behavior labels Feb 10, 2022
@boris-petrov
Copy link

I believe this issue has been resolved as of Ember 4.10. Hurray! :)

@chriskrycho
Copy link
Member

Also as of the stable types. getOwner does the right thing and provides DI lookup capabilities. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:working-as-intended Not a bug. This is the intended behavior types:core Something is wrong with the Ember type definitions
Projects
None yet
Development

No branches or pull requests

3 participants