You can do it in one of few ways. Each fits slightly odd with functions with properties but all are viable, depending on the use case:
Create the function then add the property
There is no syntax for creating a function with a property. You have to do both separately:
var sth: Something = ((n: number) => {
console.log(n + 2);
}) as Something;
sth.description = "Description";
Playground Link
The as Something assertion is needed here to tell the compiler to treat the function as Something, otherwise you cannot add the description.
This allows declaring everything at once:
var sth: Something = Object.assign(
(n: number) => {
console.log(n + 2);
},
{ description: "Description"}
);
Playground Link
Object.assign is typed to return any so the type declaration sth: Something makes sure it is treated as the correct object afterwards.
Another way to create an object and add a property. It allows more control over the property, like making it non-writable, if needed.
var sth: Something = Object.defineProperty(
(n: number) => {
console.log(n + 2);
},
"description",
{ value: "Description"}
) as Something;
Playground Link
The as Something assertion is needed because Object.defineProperty() is typed to return the same as the first argument. So it returns (n: number) => void.
Very similar to Object.defineProperty() but allows multiple properties to be configured at once.
var sth: Something = Object.defineProperties(
(n: number) => {
console.log(n + 2);
},
{
description: { value: "Description" }
}
) as Something;
Playground Link