Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript export was not found

since i updated the angular cli and nestjs versions I am getting hundreds of warnings that my custom type definitions and interfaces can not be found. But my nestjs api still works fine.

i am exporting my interface like this

export interface Role {...}

and getting this warning

WARNING in ./apps/api/src/app/users/dto/update-user.dto.ts 31:75-80
"export 'Role' was not found in '@project/api-datatypes'

my import looks like this

import { Role } from '@project/api-datatypes';

what was changed in the latest version and what do I have to do to fix those warnings?

currently i am running the following versions:

├── @angular/[email protected]
├── @nestjs/[email protected]
├── [email protected]
├── [email protected]
└── [email protected]
like image 832
MOE Avatar asked Jan 14 '21 14:01

MOE


People also ask

How do I export TypeScript?

Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.

How do I export a TypeScript class?

Use named exports to export multiple classes in TypeScript, e.g. export class A {} and export class B {} . The exported classes can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a file.

Why export default is not working?

The "export default was not found" error occurs when we try to import as default from a module that doesn't have a default export. To solve the error, make sure the module has a named export and wrap the import in curly braces, e.g. import {myFunction} from './myModule' .

What is export interface TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.


Video Answer


1 Answers

just found the solution, since typescript 3.8 introduced type-only exports/import, I need to write import type { Role } from '@project/api-datatypes'; so a simple "type" was missing

see link: https://medium.com/javascript-in-plain-english/leveraging-type-only-imports-and-exports-with-typescript-3-8-5c1be8bd17fb

like image 165
MOE Avatar answered Oct 17 '22 05:10

MOE