Looking to incorporate shelljs (via DefinitelyTyped) into my Typescript 1.5-beta project. I want to utilize the exec
function with the specified signature:
export function exec(command: string, options: ExecOptions): ExecOutputReturnValue | child.ChildProcess;
export interface ExecOutputReturnValue
{
code: number;
output: string;
}
When importing and using the library like this (which functions correctly in normal ES6 JavaScript)
import * as $ from 'shelljs';
const code = $.exec(command, { silent: true }).code;
The Typescript compiler throws
error TS2339: Property 'code' does not exist on type 'ChildProcess | ExecOutputReturnValue'
.
Is there a way to safely access .code?