Skip to content

TypeScript 3 update exposed latent issues preventing usage of @loopback/repository-json-schema #1643

@mgabeler-lee-6rs

Description

@mgabeler-lee-6rs

Description / Steps to reproduce / Feature proposal

Try to build a project that uses @loopback/repository-json-schema using today's (August 24) release

Current Behavior

The build fails thus:

> lb-tsc es2018

../../common/temp/node_modules/@loopback/repository-json-schema/dist8/src/keys.d.ts:6:75 - error TS2307: Cannot find module '../../context/node_modules/@loopback/metadata/src/types'.

6 export declare const JSON_SCHEMA_KEY: MetadataAccessor<JSONSchema, import("../../context/node_modules/@loopback/metadata/src/types").DecoratorType>;
                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

It should not fail to compile. It did not fail as of yesterday.

This looks related to #1405 -- I'm guessing it was introduced by the update to building using TypeScript 3.

More Notes

The offending release file in today's build:

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

The same file in the prior release:

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, ClassDecorator | PropertyDecorator | MethodDecorator | ParameterDecorator>;

I would also note that, AFAICT, importing MetadataAccessor from @loopback/context is not correct, it should be imported from @loopback/metadata.

Experimenting with current master (01d3a37), I can reproduce the "bad" build output building it locally. Changing repository-json-schema (package.json and src/types.ts) to fix that import issue produces a more plausible looking types.d.ts:

import { MetadataAccessor } from '@loopback/metadata';
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/metadata/src/types").DecoratorType>;

I haven't gone through running tests or auditing the code for other instances of this issue.
A quick grep of the dist* folders in a built tree suggests that packages/authentication/src/keys.ts and packages/boot/test/fixtures/application.ts need this same fix:

loopback-next$ find -type d -name dist\* | xargs fgrep -r 'import("../'
./packages/authentication/dist8/src/keys.d.ts:export declare const AUTHENTICATION_METADATA_KEY: MetadataAccessor<AuthenticationMetadata, import("../../context/node_modules/@loopback/metadata/src/types").DecoratorType>;
./packages/authentication/dist10/src/keys.d.ts:export declare const AUTHENTICATION_METADATA_KEY: MetadataAccessor<AuthenticationMetadata, import("../../context/node_modules/@loopback/metadata/src/types").DecoratorType>;
./packages/boot/dist8/test/fixtures/application.d.ts:        bootOptions?: import("../../src/interfaces").BootOptions | undefined;
./packages/boot/dist10/test/fixtures/application.d.ts:        bootOptions?: import("../../src/interfaces").BootOptions | undefined;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions