Keyword "mixing"


#1

I have seen the keyword mixing in some c3type files such as:

/**

  • api to add a comment to a UserFlagable object
  • @param [UserFlagable] objs
  •        UserFlagable objects to update
    
  • @param string comment
  •        Comment to add to the UserFlagable objects
    
  • @returns whether the call succeeded
    */
    addComment: function(objs: [mixing UserFlagable], comment: string): boolean js server

Could you explain its role and how to use it?


#2

The “mixing” keyword indicates a reference to the ultimate type mixing in the type where the declaration is made. It says “whatever the leaf type will be”.

In the example given, UserFlaggable is presumably meant to be mixed into other types, and the addComment function wants instances of the right leaf (mixing) type, not just any instances of UserFlaggable.

type A mixes UserFlaggable
type B mixes UserFlaggable

In the example above, A.addComment would end up with a signature that incorporates the leaf type information:

  addComment: function(objs: [mixing A], comment: string): boolean

It would be an error to call A.addComment with an array of Bs (or even UserFlaggable instances which aren’t also As).