Skip to main content

library_private_types_in_public_api

Invalid use of a private type in a public API.

Description

#

The analyzer produces this diagnostic when a type that is not part of the public API of a library is referenced in the public API of that library.

Using a private type in a public API can make the API unusable outside the defining library.

Example

#

The following code produces this diagnostic because the parameter c of the public function f has a type that is library private (_C):

dart
void f(_C c) {}

class _C {}

Common fixes

#

If the API doesn't need to be used outside the defining library, then make it private:

dart
void _f(_C c) {}

class _C {}

If the API needs to be part of the public API of the library, then either use a different type that's public, or make the referenced type public:

dart
void f(C c) {}

class C {}