Skip to content

TypeScript generates invalid import for re-exported types #26985

Closed
@raymondfeng

Description

@raymondfeng

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

https://github.com/strongloop/loopback-next/blob/5b27323ba420bfc500fdf9f2762e7292b96ffa0f/packages/repository-json-schema/src/keys.ts

// 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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions