Skip to content

Feature: Update @computedFrom to support typing #727

Description

@silbinarywolf

I'm submitting a feature request

  • Library Version:
    1.7.3

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    v8.11.1

  • Yarn Version:
    1.5.1

  • Language:
    TypeScript 3.0

Current behavior:
We do not get any type safety when using @computedFrom. A few blogs give users a method for extending @computedFrom manually, but why not just make this an upstream feature we can use?

What is the expected behavior?
That @computedFrom can give us type safety out-of-the-box.

https://medium.com/tech-effectory/creating-a-typed-version-of-aurelias-computedfrom-decorator-with-typescript-27219651ecee

Example:

import {computedFrom as originalComputedFrom} from "aurelia-framework"; 
export function computedFrom<T>(...rest: Array<keyof T>) { 
  return originalComputedFrom(...rest); 
}
import {computedFrom} from './typedcomputedfrom'; 
export class App { 
	public foo = "a"; 
	public bar = "b";

	@computedFrom<App>("foo") 
	public get foobar () { 
		return `${this.foo} ${this.bar}`; 
	} 
}

What is the motivation / use case for changing the behavior?

  • More bugs can be caught at compile-time, this will reduce chance of "typo" mistakes when using @computedFrom
  • Rather than individual projects adopt this pattern and import a "fake" version of @computedFrom across their codebase, it's standard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions