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

Allow inferred type exporting and/or acquiring the type of a function returned value #8154

Closed
wkrueger opened this issue Apr 18, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@wkrueger
Copy link

Hello. I'm currently writing an Angular1 app and trying to avoid the use of classes. But sometimes it seems a reasonable type-checking can only be achieved either by re-defining the "methods" via interfaces, or by using classes. Let's talk examples:

function SomeService( $someInject ) {
    $someInject.run()
    //will use this later
    var out = {
        doThis() { return 22 },
        doThat() { return 'cool'}
    }
    return out
}

function SomeConsumer( $scope , SomeService:WhatType ) {
    $scope.values = SomeService.doThis()
}

While out has an inferred type inside its function scope, I can't access it outside. While inside the function I can get type MyService = typeof out, MyService isn't accessible outside.

Another way to get the desired result there would be to fetch the type of the function returned value. Something like type MyService = typeof SomeService().

Currently my only options seem to be:
either using class style:

class SomeService {
    constructor(private $someInject) { }
    doThis() {
        this.$someInject.run()
       return 22
    }
}
function consumer(SomeService:SomeService) {
  //...
}

or by redefining the methods in an interface (+keystrokes)

interfase SomeService {
    doThis : () => number;
    doThat : () => number;
}
@wkrueger
Copy link
Author

wkrueger commented Apr 18, 2016

Related:
#4233
#6606
my bad, should have commented it there

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants