You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like to use TypeScript with all strictness checks turned on. One of them is noPropertyAccessFromIndexSignature which forces indexed types such as { [key: string]: string } to be used with element access expressions, and not property access expressions.
For example, I cannot write process.env.FOO, I must write process.env["FOO"] or TypeScript will complain.
This doesn't play well with define, as it only replaces property access expressions and not element access expressions.
Obviously, the workaround is to disable noPropertyAccessFromIndexSignature in tsconfig.json, which is precisely what I'm planning to do for now.
However, I figure this could be a gotcha for those who tend to use both process.env["FOO"] and process.env.FOO interchangeably, especially if they're migrating from webpack (which does seem to handle both with DefinePlugin).
Would this be considered a bug?
I'd be happy to try making a PR for this if that helps :)
The text was updated successfully, but these errors were encountered:
fwouts
added a commit
to fwouts/previewjs
that referenced
this issue
Feb 24, 2022
I like to use TypeScript with all strictness checks turned on. One of them is
noPropertyAccessFromIndexSignature
which forces indexed types such as{ [key: string]: string }
to be used with element access expressions, and not property access expressions.For example, I cannot write
process.env.FOO
, I must writeprocess.env["FOO"]
or TypeScript will complain.This doesn't play well with
define
, as it only replaces property access expressions and not element access expressions.Here's an example config:
This will not replace the expression
process.env["FOO"]
, so it will still appear as is in the output bundle.I tried also using:
but esbuild doesn't like it:
I've created a repository that reproduces this issue: https://github.com/fwouts/esbuild-process-env-define
Obviously, the workaround is to disable
noPropertyAccessFromIndexSignature
intsconfig.json
, which is precisely what I'm planning to do for now.However, I figure this could be a gotcha for those who tend to use both
process.env["FOO"]
andprocess.env.FOO
interchangeably, especially if they're migrating from webpack (which does seem to handle both withDefinePlugin
).Would this be considered a bug?
I'd be happy to try making a PR for this if that helps :)
The text was updated successfully, but these errors were encountered: