expo/spawn-async

Change "export = " to "export default" and require "import" or "require('spawn-async').default"

ide opened this issue · 2 comments

ide commented

We currently use the special export = syntax which assigns to module.exports but this prevents us from exporting other values, namely other type definitions. Moving to export default addresses this but on the importing side this means that require('spawn-async') will no longer work and needs to be require('spawn-async').default. For callers already using import spawnAsync from '@expo/spawn-async' there is no change for them.

Why not just Object.assign or similar on the exported value if we want to export additional values?

ide commented

The extra exported values are TS type definitions (export interface SpawnPromise {...}) and there’s nothing to assign at runtime since they are compiled away. On the consuming side you’d write:

import spawnAsync, { SpawnPromise } from '@expo/spawn-async'

The attached PR has a fuller example showing when you'd use the extra exported type definitions.