Skip to content

entryPoints type is unnecessarily restrictive #4223

@GravlLift

Description

@GravlLift

When using the JS API, the type for the entryPoints option currently is

entryPoints?: string[] | Record<string, string> | { in: string, out: string }[]

However, based on the logic in lib/shared/common.ts...

if (entryPoints) {
if (Array.isArray(entryPoints)) {
for (let i = 0, n = entryPoints.length; i < n; i++) {
let entryPoint = entryPoints[i]
if (typeof entryPoint === 'object' && entryPoint !== null) {
let entryPointKeys: OptionKeys = Object.create(null)
let input = getFlag(entryPoint, entryPointKeys, 'in', mustBeString)
let output = getFlag(entryPoint, entryPointKeys, 'out', mustBeString)
checkForInvalidFlags(entryPoint, entryPointKeys, 'in entry point at index ' + i)
if (input === undefined) throw new Error('Missing property "in" for entry point at index ' + i)
if (output === undefined) throw new Error('Missing property "out" for entry point at index ' + i)
entries.push([output, input])
} else {
entries.push(['', validateStringValue(entryPoint, 'entry point at index ' + i)])
}
}
} else {
for (let key in entryPoints) {
entries.push([key, validateStringValue(entryPoints[key], 'entry point', key)])
}
}
}

the code is currently able to handle a mixed array of strings and objects as well, a signature more akin to:

 entryPoints?: Record<string, string> | (string | { in: string, out: string })[] 

Indeed, by bypassing the typechecking on the property in the current build, passing such an array works just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions