I've done some searching, but unfortunately haven't been able to find a definitive solution to my issue. Apologies if this has already been asked before, I would appreciate any guidance you can offer.
The problem I'm facing involves a store class that I created for the current project. Here's an example of a function within it:
public getStore(store: 'FIELD1' | 'FIELD2'): State<typeof store> {
return this[store];
}
This function is accompanied by a conditional type in the following file:
export type State<T> = T extends 'FIELD1'
? Field1Type[]
: T extends 'FIELD2'
? Date
: never;
I was expecting this setup to resolve the compilation error when trying to access getStore('FIELD1').length
, as it should allow for either Field1Type[]
or Date
as potential returns. However, this isn't happening.
This situation is proving to be inconvenient for me, especially since I'm working on an Angular app and wanted to directly call this function in the component's HTML without relying on additional helpers within the script. Am I missing something here, or is this behavior expected?