Hi all. Anyone using Netsuite Fasttrack Toolkit (N...
# suitescript
d
Hi all. Anyone using Netsuite Fasttrack Toolkit (NFT) with TypeScript? in the following code:
Copy code
export class SalesOrder extends SalesOrderBase {
    @FieldType.date
    custbody_deploymentdate: Date;
    @FieldType.sublist(SOItemsSublist)
    item: Sublist<SOItemsSublist>
}
TS shows the error: TS2416: Property 'item' in type 'SalesOrder' is not assignable to the same property in base type 'SalesOrderBase'.   Type 'Sublist<SOItemsSublist>' is not assignable to type 'Sublist<ItemSublist>'.     Property 'custcol9' is missing in type 'ItemSublist' but required in type 'SOItemsSublist'. Is there a way to handle it except for
Copy code
// @ts-ignore
?
u
This error occurs when you are trying to override the type of a property that is already defined in the parent class.
d
Yes, that's true. So I need that my custom Sales Order record contained item sublist with all the standard line item fields + custcol9
Is there a right way to do that?
I mean this is working properly in runtime, I just get the compilation error
u
I think you should just rename the property in your custom sales order record. This will make sure that u are not overriding the property type in the parent class and the error should go away.
d
Yes, that was my first thought too, but looks like the property must be exactly item. When I try to rename it:
Copy code
item_cust: Sublist<SOItemsSublist>
The object looks like: {"sublistId":"item_cust"}
u
is there something wrong with this name? I mean is it causing other issues?
d
No, but it just doesn't contain any data from the Sales Order
u
I think you will need to rename it everywhere you were using the 'item'. sublistId has changed. You ll need to update your code further according to this name.
update the sublist id where you are adding data to your custom sales order record.
d
The point is that I don't have to manually add any data. All I have to do is: const newSO = new SalesOrder(context.newRecord) And then I get access to all the fields and sublists. I thought that was the main advantage of using NFT 🙂
Then, in newSO.item I get access to all the lines. But in newSO.item_cust I see nothing
u
Okay!!
s
The workaround is to mark any properties you've defined in your
SOItemSublist
as optional (i.e. append a
?
at the end of the property names in the class definition).
d
That's so easy. Thanks @stalbert!
s
Yeah, it is actually a relatively recent typescript update that introduced that restriction - I now see we need to update the readme.md to include the optional marker.