Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object destructuring named `exports` conflicts on targeting `commonjs` #34693

Open
JounQin opened this issue Oct 24, 2019 · 0 comments
Open

Object destructuring named `exports` conflicts on targeting `commonjs` #34693

JounQin opened this issue Oct 24, 2019 · 0 comments
Assignees
Labels
Bug

Comments

@JounQin
Copy link

@JounQin JounQin commented Oct 24, 2019

TypeScript Version: 3.7.0-beta

Search Terms:

Object destructuring exports

Code

export interface CopyOptions {
    targets?: Array<{
      src: string | string[]
      dest: string | string[]
      rename?: string | ((name: string, extension: string) => string)
    }>
    verbose?: boolean
    hook?: string
    copyOnce?: string
}
  
export const COPY_OPTIONS_KEYS: Array<keyof CopyOptions> = [
  'targets',
  'verbose',
  'hook',
  'copyOnce',
]

export const isCopyOptions = (
  copies: Record<string, string> | CopyOptions['targets'] | CopyOptions,
): copies is CopyOptions =>
  !Array.isArray(copies) &&
  Object.keys(copies!).every(key =>
    COPY_OPTIONS_KEYS.includes(key as keyof CopyOptions),
  )

export const config = ({ exports = {}, copies: CopyOptions = [] }) => {
    return isCopyOptions(copies)
}

Expected behavior:

No conflict of exports.isCopyOptions

Actual behavior:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.COPY_OPTIONS_KEYS = [
    'targets',
    'verbose',
    'hook',
    'copyOnce',
];
exports.isCopyOptions = (copies) => !Array.isArray(copies) &&
    Object.keys(copies).every(key => exports.COPY_OPTIONS_KEYS.includes(key));
exports.config = ({ exports = {}, copies: CopyOptions = [] }) => {
    return exports.isCopyOptions(copies);
};

Playground Link:
Playground

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.