TS1371
This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
Broken Code ❌
export class MyPerson {
constructor(
public name: string,
public age: number
) {}
}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:
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:
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.
