adopted-ember-addons / ember-cli-flash

Simple, highly configurable flash messages for ember-cli
https://www.npmjs.com/package/ember-cli-flash
MIT License
355 stars 113 forks source link

Add ambient TypeScript type information #258

Closed mike-north closed 6 years ago

mike-north commented 6 years ago

Fixes #257

Consumers will need to do the following in order to take advantage of this type information.

Explicitly indicate the type of this service with a type annotation

app/components/x-foo.ts
import Component from '@ember/component';
import ComputedProperty from '@ember/object/computed';
import { inject } from '@ember/service';
import FlashService from 'ember-cli-flash/services/flash-messages';

export default class XFooComponent extends Component {
  public flashMessages: ComputedProperty<FlashService> = inject();

  public onSuccess() {
    // Type-check is happy with this!
    this.get('flashMessages').success('Success!');
  }
}
poteto commented 6 years ago

Thanks!