Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with variable scoping using (IIFE) #17

Open
nesterow opened this issue Dec 16, 2019 · 0 comments
Open

Issue with variable scoping using (IIFE) #17

nesterow opened this issue Dec 16, 2019 · 0 comments

Comments

@nesterow
Copy link

Hello,
This issue related to variable scoping and default behaviour described in the doc.
As described in the doc I cannot re-declare constants and classes or execute the same cell twice.

ITypescript cannot know which cell is currently executing, you cannot redeclare the variables if you define with let or equivalent keywords

IJavaScript has the same behaviour, but I can get around it by using IIFE:

(() => {
    class Something {
        constructor(test){
            console.log(test)
        }
    }
    const test = 23
    console.log(test)
    new Something('test')
})()

Now, I don't know if it is specific to TypeScript, but apparently I cannot use the same trick with ITypeScript:

(() => {
   class Example {
    constructor(test = "test") {
        console.log(test);
    }
   }

    new Example();
    new Example("It works!"); 
})()

On the first call I receive expected result. But if try second time I receive following error:

Error: Conflict with a committed line: 
(() => {
^
TS2349: This expression is not callable.
  Type 'void' has no call signatures.
    at execTranspile (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/lib/kernel.js:203:27)
    at Session.transpiler [as transpile] (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/lib/kernel.js:263:37)
    at Session._runNow (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:796:39)
    at Session._run (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:766:14)
    at Session.execute (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:890:10)
    at Kernel.execute_request (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/jp-kernel/lib/handlers_v5.js:116:18)
    at Kernel.onShellMessage (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/jp-kernel/lib/jp-kernel.js:285:41)
    at Socket.<anonymous> (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/jmp/index.js:350:17)
    at Socket.emit (events.js:198:13)
    at Socket._emitMessage (/Users/nesterow/.nvm/versions/node/v10.17.0/lib/node_modules/itypescript/node_modules/zeromq/lib/index.js:640:15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant