0

In ReactTS 16.9, I have the following the function that returns parameter name only if the generic type TObject has the parameter name as key. If the key does not exist, a compile error will be raised. I always import the object first in my components and then use getPropertyName.

const Utils = {
    getPropertyName<TObject>(name: keyof TObject) {
        return name
    }
}

export default Utils

Now, I would like to have it globally, so that I can use it anywhere in any component, without having to import it first.

Do I have to eject my React webpack config? Or is there another way around it?

user3601578
  • 1,310
  • 1
  • 18
  • 29
  • 1
    Why would you want to have it globally available? What is the problem with importing it? – Johannes Klauß Nov 03 '21 at 10:40
  • For convenience reasons – user3601578 Nov 03 '21 at 10:50
  • 1
    It kind of defeats the point of modules. A decent IDE/editor should auto-import it for you. You could also add your object/function to the window variable though and extend the Window type. It's a bit hacky though – Burak Nov 03 '21 at 11:03

0 Answers0