Hypercubed / mini-signals

signals, in JavaScript, fast
MIT License
120 stars 12 forks source link

TypeScript rejecting type definition #20

Closed soletan closed 1 year ago

soletan commented 3 years ago

Using mini-signals as an apparent sub-dependency of pixi.js in a stencil.js-based project, this line of code is causing a rather strict build configuration to fail:

https://github.com/Hypercubed/mini-signals/blob/f06098f3793e90cdd7432c8ecc62f5304eb4f45d/typings/mini-signals.d.ts#L19

Error is:

[ ERROR ]  TypeScript: ./node_modules/mini-signals/typings/mini-signals.d.ts:19:2
           An export assignment cannot be used in a module with other exported elements.

     L19:       export = MiniSignal;
     L20:  }

I can safely remove this line to circumvent this build obstacle, but I assume this isn't commonly intended solution.

TheoSabattie commented 3 years ago

Hello',

Workaround: Add following configuration to the tsconfig.json (compilerOptions):

    "baseUrl": "./",
    "paths": {
      "mini-signals": [
        "node_modules/resource-loader/typings/mini-signals.d.ts"
      ]
    }
soletan commented 3 years ago

Thanks for the workaround. However, I can't reproduce this issue right now, most apparently for having upgraded stencil from 2.3 to 2.4 recently.

znorman-harris commented 3 years ago

I came across this issue when researching how to solve the same problem that I'm having with pixi.js and this dependency. See my related issue here: https://github.com/pixijs/pixi.js/issues/7305

When I add in the workaround to my tsconfig.json file it does not resolve the problem for me.

snowinmars commented 3 years ago

When I add in the workaround to my tsconfig.json file it does not resolve the problem for me.

@znorman-harris , actually it resolves my issue with pixijs 6.

The only change I made is the property files

tsconfig.json

{
  "compileOnSave": false,
  "files": [ "node_modules/resource-loader/typings/mini-signals.d.ts" ],
  "compilerOptions": {
    "baseUrl": "./",
    "strictPropertyInitialization": false,
    "strictNullChecks": false,
    "allowSyntheticDefaultImports": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2020",
    "lib": [
      "es2020",
      "es6",
      "dom"
    ],
    "paths": {
      // https://github.com/Hypercubed/mini-signals/issues/20
      "mini-signals": [
        "node_modules/resource-loader/typings/mini-signals.d.ts"
      ]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
mike-lischke commented 3 years ago

@snowinmars Your approach doesn't work with Babel (CRA based app). The "paths" member is automatically removed when I run babel build:

The following changes are being made to your tsconfig.json file:

  • compilerOptions.paths must not be set (aliased imports are not supported)
Hypercubed commented 1 year ago

New version coming