I would like to express that a paremeter should be an object or a simple value type (number, bool, string, etc.), but not a function.
If I use Object
, t
Here is an approach that defines all valid (non-function) values and then uses a recursive definition. I think this works for my case and hopefully for anyone else who comes across this question.
Example on Typescript Playground
type NoFunctionValue =
boolean
| string
| number
| null
| undefined
| NoFunctionObject
| NoFunctionArray
interface NoFunctionObject {
[key: string]: NoFunctionValue
}
interface NoFunctionArray extends Array { }
// Try putting a function anywhere in here to see error
const text: NoFunctionObject = {
bool: true,
str: 'string',
num: 7,
nul: null,
undef: undefined,
arr: [true, 'string', 7, null, undefined],
obj: {
bool: true,
str: 'string',
num: 7,
nul: null,
undef: undefined,
arr: [true, 'string', 7, null, undefined]
}
}