Generated types for context
Using the command Enable context types generation
you can configure the extension to automatically provide up to date definitions for resources in your current workspace and also for the com variables.
When executing this command for a workspace, a Types.d.ts will be generated next to the Context.ts file.
The available features are demonstrated in the following code example:
// Reference igx.eval definitions
/// <reference types="@intelligentgraphics/3d.igx.eval" />
// Explicitly reference the types file
/// <reference path="Types.d.ts" />
namespace IG.Reference {
export class Context {
// Use the type `MaterialName` defined in the Types.d.ts
// to make sure we're referring to an actually existing material here.
getDefaultMaterial(): MaterialName {
return "Fabric_Fine";
}
// Use the type `GeometryName` defined in the Types.d.ts
// to make sure we're referring to actually existing geometries here.
getGeometry(theOtherOne: boolean): GeometryName {
if (theOtherOne) {
return "Classic_Deformation_Spline_Shared_Defo";
}
return "Classic_Deformation_Linear";
}
getPillowColor(): MaterialName {
// Com variables will be defined for all available properties
// in your workspace and can be used without manually defining them. They're also
// typed concretely when possible. In this case `ComPillowColor`
// is of type MaterialName because the relevant property is defined as a `Material`.
return PillowColor;
}
static PostConfigure(
configuration: IGX.Configuration,
): ConfigurationResult {
// You can change the return type of the PostConfigure
// method to `ConfigurationResult` to verify the state you define.
return {
State: {
// This property will be automatically suggested
// and can only be configured to contain the name of a material.
PillowColor: "Brass2",
// This would be an error, because `OtherColor`
// does not exist as a property.
// OtherColor: "Test"
},
};
}
}
}