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

Is it possible to load global script? #213

Open
unional opened this issue Nov 5, 2017 · 6 comments
Open

Is it possible to load global script? #213

unional opened this issue Nov 5, 2017 · 6 comments

Comments

@unional
Copy link
Contributor

unional commented Nov 5, 2017

I tried to load a file like this and failed:

(function() {
  window['MyCompany'] = {
    component: {}
  }

  const foo: string = 'foo'
  window['MyCompany'].component.foo = foo
}())

error: 'Missing initializer in const declaration'.
If I remove the type, i.e. from const foo: string = 'foo' to const foo = 'foo', it works.

@unional
Copy link
Contributor Author

unional commented Nov 5, 2017

Repro: https://github.com/unional/domture/tree/global-script-with-type

It uses plugin-typescript internally.

@unional
Copy link
Contributor Author

unional commented Nov 5, 2017

Here is the systemjs config being used:

{
  "baseURL": "node_modules",
  "packageConfigPaths": [
    "@*/*/package.json",
    "*/package.json"
  ],
  "map": {
    "app": "./fixtures/ts"
  },
  "packages": {
    "app": {
      "defaultExtension": "ts"
    },
    "typescript": {
      "main": "lib/typescript.js",
      "meta": {
        "lib/typescript.js": {
          "exports": "ts"
        }
      }
    },
    "plugin-typescript": {
      "main": "lib/plugin.js"
    }
  },
  "transpiler": "plugin-typescript"
}

@unional
Copy link
Contributor Author

unional commented Nov 6, 2017

Seems like even when loading global ts files without typed information also have some quirks.

I don't have a repro on this one because it is related to my work, but in essence, it throws a TypeError: x is not a constructor when I create a ExtJS class and instantiates it:

// source.ts
TestClass = Ext.extends(BaseClass, { ... })

// test.ts
console.log(TestClass)
const instance = new TestClass({}) // TypeError: TestClass is not a constructor

If I load the source from transpiled js, it is working, but if I load source.ts, it gives the above error.

The console.log(TestClass) outputs are the same no matter if I am loading js or ts:

{ [Function: constructor]
      superclass:
       constructor {
         constructor:
          { [Function: constructor]
            superclass: [Object],
            override: [Function],
            extend: [Function],
            xtype: 'store',
            Error: [Object] },
         supr: [Function],
         superclass: [Function],
         override: [Function: io],
         writer: undefined,
  ...

@frankwallis
Copy link
Owner

Looking at the first issue it seems that the file is not getting passed through the transpiler, I'm not exactly sure why, but it's likely to be a configuration issue.

@unional
Copy link
Contributor Author

unional commented Nov 7, 2017

Thanks Frank.

I try to change some config as you suggest and now this one works:

{
  "baseURL": "node_modules",
  "packageConfigPaths": [
    "@*/*/package.json",
    "*/package.json"
  ],
  "map": {
    "app": "./fixtures/ts"
  },
  "packages": {
    "app": {
      "defaultExtension": "ts",
       "meta": {
         "*.ts": {
           "loader": "plugin-typescript"
         }
      }
    },
    "typescript": {
      "main": "lib/typescript.js",
      "meta": {
        "lib/typescript.js": {
          "exports": "ts"
        }
      }
    },
    "plugin-typescript": {
      "main": "lib/plugin.js"
    }
  },
  "transpiler": "plugin-typescript"
}

But I thought the meta is not necessary as by default it will go through the transpiler.
Maybe an issue with [email protected]?

I'll continue to see if the second issue is also resolved.

@unional
Copy link
Contributor Author

unional commented Nov 7, 2017

YES! that also solves the second issue.

Now the remaining question is why it doesn't work without the meta/*.ts/loader config.

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

2 participants