Deprecated in favor of verbatimModuleSyntax
.
There are some cases where TypeScript can't detect that you're using an import. For example, take the following code:
ts
import { Animal } from "./animal.js";
eval("console.log(new Animal().isDangerous())");
import { Animal } from "./animal.js";
eval("console.log(new Animal().isDangerous())");
or code using 'Compiles to HTML' languages like Svelte or Vue. preserveValueImports
will prevent TypeScript from removing the import, even if it appears unused.
When combined with isolatedModules
: imported types must be marked as type-only because compilers that process single files at a time have no way of knowing whether imports are values that appear unused, or a type that must be removed in order to avoid a runtime crash.