microsoft / microsoft/TypeScript
ThisType for Ember.computed and Ember.observer
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
TypeScript Version: 2.3.4
Thanks for your work on this great project :)
Context
We are experimenting with TypeScript 2.x in Ember, and the new TypeScript 2.x features really enable us to type most of our Ember code. There is however one thing we came across that doesn't seem like something we can solve in our interfaces/declarations:
It seems that there currently is no way to get the this context inside the Ember.computed and Ember.observer pattern.
ThisType not compatible with Ember.computed and Ember.observer?
We have set up some experimental interfaces for Ember.Object.extend() (inspired by Vue.js' type declarations, @ember/types and various other sources)
https://github.com/draios/ember-typescript2/blob/master/app/types/ember/ember-types.d.ts#L78-L83
These types/interfaces are working so far; all methods and hooks have the proper this type, and class properties are accessible through getters and setters.
However when it comes to computed properties, there seems to be no way to get the proper this context inside the function passed to Ember.computed() (see example below).
Code
export default Ember.Object.extend({
myProp: true,
myMethod: function() {
// myProp is accessible because of ThisType
this.get('someProperty');
}
computedProperty: Ember.computed('someProperty', function() {
// myProp is not accessible, because `this` is set to type <any>
let myVal = this.get('someProperty');
// ... both `this` and `myVal` are of type <any>
// and no way to fix this from an external interface?
});
});
Is this Ember pattern supported somehow in TypeScript?
Thanks!
N.B. I tried something like the following, but it doesn't work (X becomes of type {}).
// the function passed to Ember.computed
type ComputedPropertyFunc<T, X> = (this: X) => T
// Ember.computed with one observed property and a function
function computed<T, X>(observedProperty1: string, fn: ComputedPropertyFunc<T, X>): T & ThisType<X>
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par lire les déclarations expérimentales de ember-types.d.ts liées dans l’issue ainsi que le comportement de ThisType de TypeScript 2.x décrit dans les exemples. Déterminez si Ember.computed et Ember.observer peuvent recevoir le type this contextuel prévu ; le travail est terminé lorsque l’utilisation prise en charge est documentée ou que les modifications nécessaires du compilateur ou des déclarations sont identifiées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100