Code: Select all
type EventsTypes = 'click' | 'touch';
type EventHandlers = `on${Capitalize}`; // 'onClick' | 'onTouch'
import typing
@typing._SpecialForm
def Capitalize(self,*parameters):
args = [p.title() for p in typing._flatten_literal_params(parameters)]
return typing.Literal[*args]
@typing._SpecialForm
def Concat(self,parameters):
prepend = parameters[0]
types = parameters[1:]
args = [prepend+p for p in typing._flatten_literal_params(types)]
return typing.Literal[*args]
EventTypes = typing.Literal['click','touch']
EventsCapitalized = Capitalize[EventTypes]
print(EventsCapitalized) #typing.Literal["Click","Touch"] however, vscode on hover over EventsCapitalized says the type is object
EventHandlers = Concat["on",Capitalize[EventTypes]]
print(EventHandlers) #typing.Literal["onClick","onTouch"] however, vscode on hover over EventHandlers says the type is object
Ich hatte gehofft, dass jemand dies schon einmal gelöst hat.