ES Modules: Depreciate Export

As a mantainer library, I want to abandon the old export in favor of the new.

To preserve backward compatibility, I would like temporary ones to keep both exports and warn those users who are still using the old one .

Before

function foo(){}
export {foo as oldExport}

After

function foo(){}
export {foo as newExport}
export {foo as oldExport} // When user import it I'd like to fire a `console.warn`

The only solutions I came up with are to use external or to export the exported function to another deprecated function . What I don't think is optimal for a small library, like the one I'm working on.

Is there any other approach that I skipped?

+4
1

JavaScript ( ).

, , IntelliJ IDEA , , IDE - . oldExport ( ).

function foo() {}
export {foo as newExport}

/**
 * @deprecated
 */
const oldExport = foo;
export {oldExport}

. http://usejsdoc.org/tags-deprecated.html

( ), .

0

Source: https://habr.com/ru/post/1694596/


All Articles