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
Is your feature request related to a problem? Please describe.
I maintain a set of modules that export a set of types that overlap in their interfaces, both in terms of data structure and functionality.
While I can declare the type data structures in a way that lets me use "duck typing" to unify them:
Which allows me to pass either an A or a B into a method that expects an Interface. And if i'm missing a field it expects, i will get errors letting me know that i'm passing in an incompatible object.
funcinterfaceCall(interfaceMyInterface) any => doStuff(interface.sharedField)
vara = {
sharedField: 'a'otherField: false
}
// successinterfaceCall(a)
// build errorsinterfaceCall({})
However, if I want Interface to define not just the properties, but also member methods, there's really not a way to do this today. There's no way to express that the interface expects a method to be present. Best I can do is to export the same function name in all my interface-bound modules.
// a.biceptypeA = { /* same as above*/ }
@export()
funcinterfaceCall(interfaceMyInterface) any => // A-specific operation// b.bicep
@export()
typeB = { /* same as above*/ }
@export()
funcinterfaceCall(bB) any => // B-specific operation
But now, I have to know what import brought in what functions in order to call them
// main.bicepimport * asAfrom'./a.bicep'import * asBfrom'./b.bicep'paramMyInterfacexparamBbx.interfaceCall(x) // syntax errorA.interfaceCall(x) // maybe correct? I don't actually know what x isB.interfaceCall(b) // correct
Describe the solution you'd like
I would love to hear what the thoughts are on adding lambdas to the top-level data type set, since they are already present in the built-in functions like map.
signature could be lambda(paramType*) outputType
same limitations as func would be reasonable:
no var references
no resource references
Using this proposal I can express the examples above as
// interface.bicep
@export()
typeMethodType = lambda(MyInterface) any
@export()
typeType = {
sharedField: sharedFieldTypemethod: MethodType
}
// a.bicepimport * asInterfacefrom'./interface.bicep'typeA = {
sharedField: stringmethod: Interface.MethodTypeaField: bool
}
funcinterfaceCall(aA) any => // A-specific operation
@export()
funcnew(oobject) A => union({method: interfaceCall}, o)
// b.bicepimport * asInterfacefrom'./interface.bicep'typeB = {
sharedField: stringmethod: Interface.MethodTypebField: object
}
funcinterfaceCall(bB) any => // B-specific operation
@export()
funcnew(oobject) B => union({method: interfaceCall}, o)
// main.bicepimport * asAfrom'./a.bicep'import * asBfrom'./b.bicep'module_'./my-module.bicep' = {
name: '_'params:{
interface: A.new( {
sharedField: 'a'aField: true
})
}
}
// my-module.bicepimport * asInterfacefrom'./interface.bicep'paraminterfaceInterface// doesn't have to know what concrete type the object isvarresult = interface.method(interface)
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I maintain a set of modules that export a set of types that overlap in their interfaces, both in terms of data structure and functionality.
While I can declare the type data structures in a way that lets me use "duck typing" to unify them:
Which allows me to pass either an
A
or aB
into a method that expects anInterface
. And if i'm missing a field it expects, i will get errors letting me know that i'm passing in an incompatible object.However, if I want
Interface
to define not just the properties, but also member methods, there's really not a way to do this today. There's no way to express that the interface expects a method to be present. Best I can do is to export the same function name in all my interface-bound modules.But now, I have to know what import brought in what functions in order to call them
Describe the solution you'd like
I would love to hear what the thoughts are on adding
lambdas
to the top-level data type set, since they are already present in the built-in functions likemap
.lambda(paramType*) outputType
func
would be reasonable:var
referencesUsing this proposal I can express the examples above as
The text was updated successfully, but these errors were encountered: