Effect CommunityEC
Effect Community3y ago
16 replies
fubhy

Importing Namespaces with Dynamic Imports

Is anyone aware of any way to import namespaces with dynamic imports?

E.g. this is invalid:

    const Brand = await import("effect/Brand")
    
    type Int = number & Brand.Brand<"Int">
    
    const Int = Brand.refined<Int>(
      (n) => Number.isInteger(n),
      (n) => Brand.error(`Expected ${n} to be an integer`)
    )
    
    assert.strictEqual(Int(1), 1)
    assert.throws(() => Int(1.1))


But this is fine:

    import * as Brand from "effect/Brand"
    
    type Int = number & Brand.Brand<"Int">
    
    const Int = Brand.refined<Int>(
      (n) => Number.isInteger(n),
      (n) => Brand.error(`Expected ${n} to be an integer`)
    )
    
    assert.strictEqual(Int(1), 1)
    assert.throws(() => Int(1.1))
Was this page helpful?