Closed
Description
The issue was reported on #24941 (comment). It was initially discovered in loopbackio/loopback-next#1643.
In this case, MetadataAccessor is exported from @loopback/metadata and re-exported by @loopback/context. Please note that @loopback/repository-json-schema module imports MetadataAccessor from @loopback/context. It leads to incorrectly generated code.
TypeScript Version: 3.0.x and up
Search Terms: TypeScript import types
Code
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
Expected behavior:
TypeScript generates the following code:
import { MetadataAccessor } from '@loopback/context';
import { JSONSchema6 as JSONSchema } from 'json-schema';
/**
* Metadata key used to set or retrieve repository JSON Schema
*/
export declare const JSON_SCHEMA_KEY: MetadataAccessor<JSONSchema, import("@loopback/context").DecoratorType>;
Actual behavior:
TypeScript generates invalid code as follows:
import { MetadataAccessor } from '@loopback/context';
import { JSONSchema6 as JSONSchema } from 'json-schema';
/**
* Metadata key used to set or retrieve repository JSON Schema
*/
export declare const JSON_SCHEMA_KEY: MetadataAccessor<JSONSchema, import("../context/node_modules/@loopback/metadata/src/types").DecoratorType>;
Playground Link:
Related Issues:
#24874