I encountered an error message
Cannot redeclare block-scoped variable 'reducer'
when running sample code from a book using tsc
. I'm unsure of the reason behind this issue.
tsc -v
// Version 2.1.0-dev.20160726
Next, I executed ts-node in the following manner:
ts-node 01-identity-reducer.ts
In file 01-identify-reducer.ts:
interface Action {
type: string;
payload?: any;
}
interface Reducer<T> {
(state: T, action: Action): T;
}
let reducer: Reducer<number> = (state: number, action: Action) => {
return state;
};
console.log( reducer(0, null) ); // should output -> 0
ERROR
TSError: ⨯ Unable to compile TypeScript
01-identity-reducer.ts (10,5): Cannot redeclare block-scoped variable 'reducer'. (2451)
at getOutput (/Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/index.ts:258:17)
at /Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/index.ts:267:16
at Object.compile (/Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/index.ts:403:17)
at loader (/Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/index.ts:289:33)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/index.ts:306:14)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at Object.<anonymous> (/Users/person/.nvm/versions/node/v5.0.0/lib/node_modules/ts-node/src/_bin.ts:179:12)
at Module._compile (module.js:425:26)