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

angular directive changes, still missing #2605 #2607

Merged
merged 7 commits into from
Aug 10, 2014

Conversation

pocesar
Copy link
Contributor

@pocesar pocesar commented Aug 2, 2014

tabs to spaces, fix white space, separate link and compile interfaces to be casteable

@pocesar
Copy link
Contributor Author

pocesar commented Aug 4, 2014

guess this is related to #2618

controller: any,
transclude: ITranscludeFunction
) => void;
link?: IDirectivePrePost;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this basically makes link compatible with anything that doesn't have pre or post members. E.g. link : 'bad' will compile. I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the bad side of Javascript, you can have all, and Typescript won't allow you to have all heh. making it (): IDirectivePrePost; doesnt help either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here : #2605 you had :

interface IDirectiveLink {
        (): IDirectiveLinkFunction;
        pre?: IDirectiveLinkFunction;
        post?: IDirectiveLinkFunction;
    }

I take it that (): IDirectiveLinkFunction; didn't test well?

In this PR : Seems we are saying either you can have old safety for link OR you can have the new safety for pre/post. If this is the case I prefer the old safety since link is used much more than pre/post. Correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, but angular docs say that the best practice is to always return an object of pre/post... that's the confusion.
https://docs.angularjs.org/api/ng/service/$compile#comprehensive-directive-api

Best Practice: It's recommended to use the "directive definition object" form.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to use the "directive definition object" form.

I am happy with the compile definition you have added 👍 That can follow the definition object form. Just don't like it for the link function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, will change it then

instanceAttributes?: IAttributes,
controller?: any,
transclude?: ITranscludeFunction
): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks. One more fix. Don't mark these arguments as optional (http://definitelytyped.org/guides/best-practices.html callback signatures)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright
@basarat It seems it's not possible to create an overloaded function declaration, trying to use

    interface IDirectiveLinkFn {
        (
            scope: IScope,
            instanceElement: IAugmentedJQuery,
            instanceAttributes: IAttributes,
            controller: any,
            transclude: ITranscludeFunction
        ): void;
        (
            scope: IScope,
            instanceElement: IAugmentedJQuery,
            instanceAttributes: IAttributes,
            controller: any
        ): void;
        (
            scope: IScope,
            instanceElement: IAugmentedJQuery,
            instanceAttributes: IAttributes
        ): void;
        (
            scope: IScope,
            instanceElement: IAugmentedJQuery
        ): void;
        (
            scope: IScope
        ): void;
        (): void;
    }

but the compiler won't let me use just scope for example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be just :

   interface IDirectiveLinkFn {
        (
            scope: IScope,
            instanceElement: IAugmentedJQuery,
            instanceAttributes: IAttributes,
            controller: any,
            transclude: ITranscludeFunction
        ): void;
  }

Demo that it accommodates all:

interface IDirectiveLinkFn {
        (
            scope: any,
            instanceElement: any,
            instanceAttributes: any,
            controller: any,
            transclude: any
        ): void;
  }

  var foo : IDirectiveLinkFn;

  foo = ()=>{};
  foo = (scope)=>{};
  // And so on 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I'm overthinking this. The next commit should have fixed it.

directive interface definition and tests
@@ -316,6 +316,7 @@ declare module ng {
// see http://docs.angularjs.org/api/ng.$rootScope.Scope
///////////////////////////////////////////////////////////////////////////
interface IScope {
[index: string]: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pocesar This doesn't add any value IMHO:

interface IScope1 {
       [index: string]: any;
       $apply(): any;
}
interface IScope2 {
       $apply(): any;
}

var scope1:IScope1;
scope1['foo'] = 123;

var scope2:IScope2;
scope2['foo'] = 123;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on typescript 1.0.1 with --noImplicitAny, that fails, therefore you should explicitely define that the interface expects anything to be added to it.

test.ts(13,8): error TS7017: Index signature of object type implicitly has an 'any' type.

rootscope <> iscope
basarat added a commit that referenced this pull request Aug 10, 2014
angular directive changes, still missing #2605
@basarat basarat merged commit a2dcd79 into DefinitelyTyped:master Aug 10, 2014
@basarat
Copy link
Member

basarat commented Aug 10, 2014

@pocesar thanks mate! Just wondering about the need for the following:

this: IRootScopeService;

@pocesar
Copy link
Contributor Author

pocesar commented Aug 10, 2014

it's part of the rootscope, "this" always point to the scope itself, like $root points to $rootScope, yadda yadda

@basarat
Copy link
Member

basarat commented Aug 10, 2014

it's part of the rootscope, "this" always point to the scope itself,

Indeed it does. Tested : http://jsfiddle.net/vuy3sv0g/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants