You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript error when trying to configure optional sinks #75
I'm trying to create conditional configurations for LogTape based on environment variables but keep bumping up against the TypeScript error about types being incompatible.
This is the closest that I've got.
letsinks:
|Record<'console'|'syslog',Sink>|Record<'console'|'syslog'|'file',Sink>={console: getConsoleSink(),syslog: getSyslogSink(),};letloggers=[{category: ['logtape','meta'],sinks: ['syslog'],},{category: appName,lowestLevel: 'debug',sinks: ['console'],},]if(logFile){sinks={
...sinks,file: getFileSink(`${logDir}/${logFile}`),};loggers=[loggers[0],{category: appName,lowestLevel: 'debug',sinks: ['console','file'],}]}awaitconfigure({
sinks,
loggers,// ^^^^^^^ Complains about "Type 'string' is not assignable to type '"console" | "syslog"'."});
Is there a way around this? Or is the only option to call await configure in an if-else statement? i.e.
if(logFile){awaitconfigure(...);// Invoke with file sink.}else{awaitconfigure(...);// Invoke without file sink.}
Activity
dahlia commentedon Jul 22, 2025
How about this?
rojakcoder commentedon Jul 22, 2025
That works! The gist is to create a placeholder function for the key that is added later.