Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent devs from using a global?

I have a TypeScript project that uses a custom wrapper over chrome.runtime.sendMessage to send messages. This custom wrapper makes sure the messages are formatted correctly, are safe, etc.

However there is a lot of turnaround of devs in the codebase and new devs often try to use chrome.runtime.sendMessage directly (and not the wrapper).

Is there any way I can display a warning, either at compile time or in their IDE, when they try to access that method?

like image 783
jsco Avatar asked Feb 03 '26 09:02

jsco


1 Answers

You can use type annotation, below is an example used to avoid new Buffer(number) for Node.js

interface BufferConstructor {
        /**
         * Allocates a new buffer of {size} octets.
         *
         * @param size count of octets to allocate.
         * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
         */
        new (size: number): Buffer;
}

If you use it, The IDE will give you a warning: enter image description here

like image 179
Mehriddin Nozimov Avatar answered Feb 05 '26 23:02

Mehriddin Nozimov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!