-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Is transform overload unnecessary? #3089
Comments
If you look at the export interface TransformResult<SpecificOptions extends TransformOptions = TransformOptions> {
code: string
map: string
warnings: Message[]
/** Only when "mangleCache" is present */
mangleCache: Record<string, string | false> | (SpecificOptions['mangleCache'] extends Object ? never : undefined)
/** Only when "legalComments" is "external" */
legalComments: string | (SpecificOptions['legalComments'] extends 'external' ? never : undefined)
} So, it makes sure the result object has let r = await esbuild.transform('', {})
r.mangleCache // record | undefined
r.legalComments // string | undefined
let t = await esbuild.transform('', {
mangleCache: {},
legalComments: 'external',
})
r.mangleCache // record
r.legalComments // string |
@hyrious , But |
@zoeyzhao19 Please look carefully. They are optional if you don't pass in let t = await esbuild.transform('', {
mangleCache: { someProp_: false },
legalComments: 'external',
})
let comments = t.legalComments.trim()
// because t.legalComments must be string, so calling .trim() on it is ok |
esbuild
transform
api has an overload type declarationWhich I might think it respect custom options extended from
TransformOptions
, But when I pass my option which is extended fromTransformOptions
,My custom option could not pass and it reported Error: Invalid option in transform() call: "customOptionFlag".
and my ts check does not report the wrong type. Since esbuild does not handle user's custom transform option, so I doubt that whether is this transform overload necessary.
The text was updated successfully, but these errors were encountered: