Type-only imports in migration files
In the Kysely documentation, an example is given of a migration file which imports
Kysely
from the kysely
package. This import is only used to type the up
and down
functions, but not as a value. Depending on the TypeScript verbatimModuleSyntax
compiler option, this may or may not result in a runtime import in the compiled code, which in the worst case could mean different behaviors of the migration script.
My question is: Is it safe to import Kysely
with a type-only import in migration files? If not, what side effects of the import are needed in such files?
If the idea (as I suspect) is indeed only to import the Kysely
type for typing the function arguments, I suggest also that the example should be changed to use a type-only import or accompanied by a note about the possibility of such an import.Migrations | Kysely
Migration files should look like this:
3 Replies
As a side note, the consistent-type-imports rule from typescript-eslint will raise warnings/errors about this with its default settings (which is how I found this issue).
consistent-type-imports | typescript-eslint
Enforce consistent usage of type imports.
Solution
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Thank you for the quick reply! Also (I should have done this in the original post), I'd like to thank you and the other maintainers for creating and maintaining Kysely. IMO it is a huge contribution to the TS ecosystem and a brilliant use of the typing system. For each hour you spend working on it I wouldn't be surprised if you save a hundred in debugging and documentation searches for the developers using it.