-
Notifications
You must be signed in to change notification settings - Fork 643
Description
Objection 2.1.5
Typescript 3.9.3
Issue:
When using mixins in Typescript the compiler gets confused about the 'Knex' type, throwing the following error: Return type of exported function has or is using name 'Knex' from external module [...] but cannot be named.ts(4058)
How to reproduce
import { Model } from 'objection';
export function Mixin(options = {}) {
return function<T extends typeof Model>(Base: T) {
return class extends Base {
mixinMethod() {}
};
};
}Taking the Mixing example from the homepage, dropping it into a fresh project. (Note: the example appears to have other issues, at least in TS 3.9.3, but those I can solve... the Knex error however won't go away no matter what I do.) For all other purposes, typings appear to work, however.
Experimenting a little with Objections typings I could solve the issue by replacing:
import * as knex from 'knex';
import Knex = require('knex');
in index.d.ts with:
import knex from 'knex'
In my project that solved the issue with the Knex error without adding any others... but it is a little weird. Though I guess the second import is a strange combo of commonJS and ES Modules... so that may throw the compiler?
Further Info
Some background to the issue: microsoft/TypeScript#5711