-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be Able To Define Custom Interface Definition Creation #44
Comments
With XrmDefinitelyTyped we generate typings (i.e. a .d.ts file) for each form. There is thus no need to explicitly check if a field is on the form, since e.g. This should eliminate the need for explicitly checking if a field is on the form, since we already know it is. In theory the field could still have been removed from the form since the last time you generated the typings with XrmDefinitelyTyped. We eliminate any possible errors by ensuring that we run XrmDefinitelyTyped and build our VS solution as part of our deployment pipeline. Do you see any other use cases for creating custom interface definitions in XrmDefinitelyTyped? |
True point, here is a couple counters.
|
export function ForAllControls<T>(attr: Xrm.Attribute<T>, f: (c: Xrm.Control<Xrm.Attribute<T>>) => any) {
attr.controls.forEach(x => f(x));
}
ForAllControls(Page.getAttribute("accountnumber"), x => x.setDisabled(true)); This way you piggyback on the typings of XDT, such that you don't have to define the methods that are available on a control.
export function AddAndFire<T>(attr: Xrm.Attribute<T>, onChange: (c: Xrm.ExecutionContext<Xrm.Attribute<T>> | undefined) => any) {
attr.addOnChange(onChange);
attr.fireOnChange();
}
AddAndFire(Page.getAttribute("accountnumber"), fooChange); As a general comment, we see the potential for allowing injection of interfaces like declare namespace MyLibrary {
function setValue(attrName: "name", value: string);
function setValue(attrName: "phonenumber", value: number);
function setValue(attrName: "somedate", value: Date);
} But for different use cases than the ones you described. |
I was not aware of 1. Thanks for pointing it out. 2, 3, and 5 are all workarounds that I'm not particularly excited about, but definitely aren't bad either. Thanks for the through explanation and examples. |
Got an idea over the weekend that I believe solves this, and it should also be quite simple to implement in XDT. Basically, XDT just needs to generate an interface for each collection (attributes, controls, etc) for all form, that maps the key of the object to the wanted type. The custom library should be defined to utilize these interfaces, by using In a form-script, the developer just has to declare the library to be of the wanted form-type (pretty much like you would do with Here is a gist with an example: https://gist.github.com/mktange/4878da0477dc1244a273af7359ec10b2 |
Fixed in 53fc582 |
Null Safe Code like this is really annoying
Which is why I've seen lots of people creator nullsafe helper functions:
These functions may log if the attribute isn't on the form, but it won't throw a null ref exception.
Is there a way to get the generated d.ts files, to create interface definitions for these custom library calls?
The text was updated successfully, but these errors were encountered: