Remixes with the Typescript annotation
Overview
When remixing a Type with a TypeScript implementation, you can override or concatenate the existing implementations of the Type with the new TypeScript implementation.
Override original implementation
Annotate the Type with @typeScript(sourceCodeType="Module")
This will entirely override all existing functions, and replace them with the functions in your overriding Typescript file.
Append to original implementation
Annotate the type with @typeScript(sourceCodeType="Script")
Note that you cannot override existing functions using this method, because that will result in duplicate functions with the same name, which is not supported in Typescript. Rather, you can only add new functionality. Note that you cannot use EcmaScript Modules (i.e., imports and exports) with this annotation value.
Examples
1) Completely change the implementation of an existing type
Assuming you have a package foo which depends on package bar:
In bar package:
// UiSdlDataGrid.c3typ
@typeScript
type UiSdlDataGrid {
myFuncToKeep: function (): string ts-client
myFuncToOverride: function (): string ts-client
}// UiSdlDataGrid.ts
export function myFuncToKeep() {
return 'base package'
}
export function myFuncToOverride() {
return 'base package';
}In foo package:
// UiSdlDataGrid.c3typ
@typeScript(sourceCodeType="Module")
remix type UiSdlDataGrid {
newMethod: function (): string ts-client
}// UiSdlDataGrid.ts
// myFuncToKeep and myFuncToOverride will not exist on new implementation!
export function newMethod() {
return 'foo';
}2) Add a new method to an existing type
Assuming you have a package foo which depends on package bar:
In bar package:
// UiSdlDataGrid.c3typ
@typeScript
type UiSdlDataGrid {
myFuncToKeep: function (): string ts-client
myOtherFuncToKeep: function (): string ts-client
}// UiSdlDataGrid.ts
function myFuncToKeep() {
return 'base package'
}
function myOtherFuncToKeep() {
return 'other base package';
}In foo package:
// UiSdlDataGrid.c3typ
@typeScript(sourceCodeType="Script")
remix type UiSdlDataGrid {
myNewFunc: function (): string ts-client
}// UiSdlDataGrid.ts
// All three functions will exist on final typescript implementation:
// myFuncToKeep, myOtherFuncToKeep, myNewFunc
function myNewFunc() {
return 'foo';
}3) Change a single method on an existing type - approach 1
The annotation value sourceCodeType="Script" is intended to be used with files that don't use import or export statements. If you choose knowingly to use it even when the original implementation or your file uses import or export, you must ensure your new file doesn't have any conflicting definitions with the original file.
Assuming you have a package foo which depends on package bar:
In bar package:
// UiSdlDataGrid.c3typ
@typeScript
type UiSdlDataGrid {
myFuncToKeep: function (): string ts-client
myFuncToOverride: function (): string ts-client
}// UiSdlDataGrid.ts
function myFuncToKeep() {
return 'base package'
}
function myFuncToOverride() {
return 'base package';
}In foo package:
// UiSdlDataGrid.c3typ
@typeScript(sourceCodeType="Script")
remix type UiSdlDataGrid// UiSdlDataGrid.ts
function myFuncToOverride() {
return 'different functionality for extending package';
}4) Change a single method on an existing type - approach 2
Use this approach if the original implementation is a module, i.e., it uses export statments. Note that you will need to copy over any original implementations that you wish to be available in the remixed file, since the original implementation will be entirely overwritten by the new implementations.
Assuming you have a package foo which depends on package bar:
In bar package:
// UiSdlDataGrid.c3typ
@typeScript
type UiSdlDataGrid {
myFuncToKeep: function (): string ts-client
myFuncToOverride: function (): string ts-client
}// UiSdlDataGrid.ts
export function myFuncToKeep() {
return 'base package'
}
export function myFuncToOverride() {
return 'base package';
}In foo package:
// UiSdlDataGrid.c3typ
@typeScript(sourceCodeType="Module")
remix type UiSdlDataGrid// UiSdlDataGrid.ts
export function myFuncToKeep() {
return 'base package'
}
export function myFuncToOverride() {
return 'different functionality for extending package';
}