Typescript named parameters used in angularjs?

I am trying to learn both typescript and angularjs (and therefore javascript as I am noob)

going through the angularjs tutorials, I see that they do such things:

in plain javascript:

    //for full example, see the "Wire up a backend" project.js example 
//on the main page of http://angularjs.org 
            function CreateCtrl($scope, $location, Project){
        //do stuff
        }

kicker, these parameters can be in any order (or none at all), and Project is actually a user-defined variable / type. The angularjs framework is able to map parameters to real objects.

So now, to Typescript, how can I recreate this type of functionality? I would really like to describe the behavior of angularjs in some way, to allow me to wrap it in Typescript (strongly introduce this flexible property injection)

any ideas?

+5
source share
1

AngularJS type , Angular TypeScript.

, ( ), , , ( , JavaScript ) , , , :

interface Example {
    ($scope: bool, $location: string, Project: number): void;
    ($location: string, $scope: bool, Project: number): void;
    (Project: number, $scope: bool, $location: string): void;
}

declare var example: Example;

example(, intellisense , , .

JavaScript , , , , ...

interface ExampleArguments {
    scope: bool;
    location: string;
    project: number;
}

var example = function (exampleArguments: ExampleArguments) {

};

example({ scope: true, project: 4, location: 'hi' });

TypeScript.

+6

All Articles