How to make package built on top of TS 4.X compatible with 3.X? Like, if you have newer version -> use new features, else -> use any or unknown or whatever is supported in older version.
Is there any possibility to use directives for that purpose?
There is no way to switch between supported and unsupported features in TypeScript.
For instance, if you have a library which is built on top of TS 4.0 with variadic tuple types there is no way to use it in a package where TS 3.0 is used.
However, you can maintain two versions of your typings: before TS4 and after TS4. For instance, take a look how lodash or react maintaince several versions of typings.
You can just use an install an older version (whatever you want it to be, example: `npm i --dev typescript@3.5.2) of typescript in your npm and try to fix the errors. Then revert the typescript version to v4 or whatever it was already.
Now your code is compatible with the designated older typescript version (just make sure the functionality of your code doesn't change while updating it).