Skip to content

Typescript compilation emit a new import with a wrong path while the type is already imported before #27136

@pradel

Description

@pradel

Description

Typescript compilation emit a new import for an inferred type with a wrong path while the type is already imported before at the top of the file.

TypeScript Version: 3.0.3

Search Terms:

  • declaration path

Code

import { emailTemplates } from './utils/email';

const defaultOptions = {
  tokenSecret: 'secret',
  tokenConfigs: {
    accessToken: {
      expiresIn: '90m',
    },
    refreshToken: {
      expiresIn: '7d',
    },
  },
  // Type is inferred here
  emailTemplates,
  userObjectSanitizer: (user: User) => user,
  sendMail,
  siteUrl: 'http://localhost:3000',
};

Expected behavior:

// ...
import { EmailTemplateType } from './types/email-template-type';
declare const defaultOptions: {
    tokenSecret: string;
    tokenConfigs: {
        accessToken: {
            expiresIn: string;
        };
        refreshToken: {
            expiresIn: string;
        };
    };
    emailTemplates: EmailTemplateType;
    userObjectSanitizer: (user: User) => User;
    sendMail: (mail: object) => Promise<void>;
    siteUrl: string;
};
// ...

Actual behavior:

// ...
import { EmailTemplateType } from './types/email-template-type';
declare const defaultOptions: {
    tokenSecret: string;
    tokenConfigs: {
        accessToken: {
            expiresIn: string;
        };
        refreshToken: {
            expiresIn: string;
        };
    };
    emailTemplates: import("@accounts/server/src/types/email-templates-type").EmailTemplatesType;
    userObjectSanitizer: (user: User) => User;
    sendMail: (mail: object) => Promise<void>;
    siteUrl: string;
};
// ...

How to reproduce:

  • git clone https://github.com/accounts-js/accounts
  • cd accounts
  • Setup the repo, run yarn
  • Setup lerna, run yarn setup
  • Then compile with tsc, run yarn compile
  • Open packages/server/lib/accounts-server.d.ts to see the error

Happy to provide more infos if needed thanks :)

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