I attempted to provide a type definition that defines an object as any
, because as of now it's fairly open-ended as to what it could be. As well, it has a key for a property within this object.
type Props = {
obj: any;
objKey: keyof typeof obj;
};
The result is an error on the line for objKey
stating:
Cannot find name 'obj'
If I use this inline with the function arguments, it works without issue as seen below.
({ obj, objKey }: { obj: any; objKey: keyof typeof obj })
Why would this error/warning by produced in the lone type definition, and not the inline argument typing?
You should use a generic type parameter: