Question: I want to create a function object, which also has some properties held on it. For example in JavaScript I would do:

```
var f = function() { }
f.someValue = 3;

```

Now in TypeScript I can describe the type of this as:

```
var f: { (): any; someValue: number; };

```

However I can't actually build it, without requiring a cast. Such as:

```
var f: { (): any; someValue: number; } =
    <{ (): any; someValue: number; }>(
        function() { }
    );
f.someValue = 3;

```

How would you build this without a cast?

Answer: 
This is easily achievable now (typescript 2.x) with `Object.assign(target, source)`

example: 

[![enter image description here](https://i.stack.imgur.com/9EtVw.png)](https://i.stack.imgur.com/9EtVw.png)

The magic here is that `Object.assign<T, U>(t: T, u: U)` is typed to return the *intersection* `T & U`. 

Enforcing that this resolves to a known interface is also straight-forward. For example: 

```
interface Foo {
  (a: number, b: string): string[];
  foo: string;
}

let method: Foo = Object.assign(
  (a: number, b: string) => { return a * a; },
  { foo: 10 }
); 

```

which errors due to incompatible typing: 

> 
> Error: foo:number not assignable to foo:string   
> 
>  Error: number not assignable to string[] (return type)
> 
> 
> 

*caveat: you may need to [polyfill](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) Object.assign if targeting older browsers.*
As a shortcut, you can dynamically assign the object value using the ['property'] accessor:

```
var f = function() { }
f['someValue'] = 3;

```

This bypasses the type checking. However, it is pretty safe because you have to intentionally access the property the same way:

```
var val = f.someValue; // This won't work
var val = f['someValue']; // Yeah, I meant to do that

```

However, if you really want the type checking for the property value, this won't work.