TS1371

This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.

Broken Code ❌

MyPerson.ts
export class MyPerson {
  constructor(
    public name: string,
    public age: number
  ) {}
}
printAge.ts
import { MyPerson } from './MyPerson';
 
export function printAge(person: MyPerson) {
  console.log(person.age);
}

Fixed Code ✔️

Solution 1:

When "importsNotUsedAsValues" is set to "error" in your "tsconfig.json", then you have to use the "import type" syntax when you just want to refer to a type instead of using it as a value:

printAge.ts
import type { MyPerson } from './MyPerson';
 
export function printAge(person: MyPerson) {
  console.log(person.age);
}

Solution 2:

Use the class also as a value and not just a type:

printAge.ts
import { MyPerson } from './MyPerson';
 
export function printAge(person: MyPerson) {
  console.log(person.age);
}
 
const benny = new MyPerson('Benny', 35);
printAge(benny);

Solution 3:

You can also set "importsNotUsedAsValues" to "preserve" which is not recommended.