TS1363

error TS1363: A type-only import can specify a default import or named bindings, but not both.

Broken Code ❌

1
2
3
4
5
import type MyDog, {MyPerson} from './MyPerson';

export function printAge(personOrDog: MyPerson | MyDog) {
console.log(personOrDog.age);
}

Fixed Code ✔️

With type-only imports and exports you cannot use a default import together with a named import in one single line of code. The TypeScript team chose this limitation to avoid ambiguity. You will have to use separate import statements:

1
2
3
4
5
6
import type {MyPerson} from './MyPerson';
import type MyDog from './MyPerson';

export function printAge(personOrDog: MyPerson | MyDog) {
console.log(personOrDog.age);
}