So, according to your comment, you want something like "an object which is not a function". TypeScript doesn't currently have negated types, so there's no concise way to express "not a function". Depending on your use case, you might just want to shrug and move on.
Or, you might try to force TypeScript to bend to your will with a workaround.
The simplest workaround is to find some property that functions always have and declare that your type has an incompatible optional property of the same name. For example:
type NoCall = { call?: number | string | boolean | null | undefined, [k: string]: any };
const okay: NoCall = { a: 4 }; // okay
const err: NoCall = () => 2; // error
A drawback is that you'd lose the ability to validate some legitimate non-functions (in the above case, {call: ()=>0} is not a function but would fail to validate as a NoCall). But maybe some false positives are okay for your use case?
Anyway, reasonable choices according to the standard library lib.es5.d.ts for property names to check are apply, call, bind, arguments, and caller.
If you don't like giving up one of those names, you could optionally use global augmentation to add a phantom property to the Function interface:
declare global {
interface Function {
'*FunctionsHaveThis*': true
}
}
type ObjNotFunction = { '*FunctionsHaveThis*'?: never, [k: string]: any };
const okay: ObjNotFunction = { a: 4 }; // okay
const err: ObjNotFunction = () => 2; // error
which makes property name collisions less likely but pollutes the global namespace and makes this workaround considerably less simple.
Another workaround is to use a trick with conditional types which prevent a function from being passed as a parameter to another function:
function noFunctionsPlease<T extends object>(t: T & (T extends Function ? never : T)) {
// do something with t
}
noFunctionsPlease({ a: 4 }); // okay
noFunctionsPlease(() => 2); // error
The type of t is more or less exactly saying "an object that isn't a function", but it can only be expressed as a function argument.
Hope one of those helps you or gives you an idea about how (or whether) to proceed. Good luck!
Record<string, any>Exclude<Record<string, any>, Function>but that still allows a function.