Open unional opened 7 years ago
Repro: https://github.com/unional/domture/tree/global-script-with-type
It uses plugin-typescript
internally.
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"
}
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,
...
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.
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 systemjs@0.20.19
?
I'll continue to see if the second issue is also resolved.
YES! that also solves the second issue.
Now the remaining question is why it doesn't work without the meta/*.ts/loader
config.
I tried to load a file like this and failed:
error: 'Missing initializer in const declaration'. If I remove the type, i.e. from
const foo: string = 'foo'
toconst foo = 'foo'
, it works.