I am working with an interface:
interface I {
// Question: My main focus is on restricting the input parameters
fn: (s: string) => any
val: any
}
The purpose of this interface is to simply ensure that
val
exists, without specifying its type- Verify that
fn
is a function which takes astring
, but without specifying the return type
For example, using this interface would look like:
const demo = {
fn: (s: string) => s.length,
val: new Date()
}
const example1: I = demo
example1.fn // (property) I.fn: (s: string) => any
example1.val // (property) I.val: any
demo.fn // (property) fn: (s: string) => number
demo.val // (property) val: Date
Is there a way to replace any
so that both example1
and demo
have specific types?
Could it be done with satisfies
? What about for those on older versions before 4.9 or when dealing with "legacy" code?