diff --git a/.changeset/clever-turtles-shake.md b/.changeset/clever-turtles-shake.md new file mode 100644 index 000000000000..2f95b32ed866 --- /dev/null +++ b/.changeset/clever-turtles-shake.md @@ -0,0 +1,8 @@ +--- +"wrangler": patch +--- + +refactor: tidy up the typings of the build result in dev + +In #262 some of the strict null fixes were removed to resolve a regression. +This refactor re-applies these fixes in a way that avoids that problem. diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index ea46847ecac7..618bada44c2e 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -441,7 +441,7 @@ function useEsbuild(props: { const { entry, destination, staticRoot, jsxFactory, jsxFragment } = props; const [bundle, setBundle] = useState(); useEffect(() => { - let result: esbuild.BuildResult; + let result: esbuild.BuildResult | undefined; async function build() { if (!destination || !entry) return; const moduleCollector = makeModuleCollector(); @@ -508,9 +508,7 @@ function useEsbuild(props: { // so this is a no-op error handler }); return () => { - if (result && result.stop) { - result.stop(); - } + result?.stop?.(); }; }, [entry, destination, staticRoot, jsxFactory, jsxFragment]); return bundle;