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

Re-exporting a sub-module #119

Closed
incetarik opened this issue May 3, 2022 · 4 comments
Closed

Re-exporting a sub-module #119

incetarik opened this issue May 3, 2022 · 4 comments

Comments

@incetarik
Copy link

Hello,
I was trying to have my utility functions along with the library function, so I have created a barrel file (index ) to export everything from the files I had and a sub-module of this library, like Record.

When I use TypeScript, there is no type error but I cannot get it work if I have the following setup:

// index.ts file in utility functions folder for Record structures

export * from './some-func-file'
export * from './another-func-file'

// The following does not have any type error
// but does not work when it is compiled
export * from 'fp-ts-std/Record'
@samhh
Copy link
Owner

samhh commented May 4, 2022

We use this exact same pattern at work without issue. What bundler/environment are you using?

@incetarik
Copy link
Author

We use this exact same pattern at work without issue. What bundler/environment are you using?

I get this error when I want to use these with Jest (ts-jest more accurately).
I'll provide you my configurations now maybe that helps.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "incremental": true,
    "skipLibCheck": true,
    "noImplicitOverride": true,
    "rootDir": "./",
    "outDir": "./dist",
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "strict": true,
    "declarationMap": true,
    "moduleResolution": "node",
    "typeRoots": [
      "node_modules/@types",
      "../@types"
    ],
    "paths": {
      "@core": [
        "."
      ],
      "@core/*": [
        "./*"
      ]
    }
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

package.json, "jest" section:

"jest": {
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "@relmify/jest-fp-ts",
      "jest-extended/all"
    ],
    "moduleFileExtensions": [
      "js",
      "ts",
      "json"
    ],
    "moduleNameMapper": {
      "^@core(.*)": "<rootDir>/..$1"
    },
    "moduleDirectories": [
      "node_modules",
      "<rootDir>"
    ],
    "rootDir": "test",
    "testRegex": ".*\\.test\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage"
  }

So I have this configuration and with these, when I try to re-export from the record/index.ts file, along with my additional utility functions, that export is not usable in this way, of course it should work as also there is no type error but I would like to know your ideas about this as well.

This information might be useful:

  • My project is consisting of two sub-projects, so one is referencing the other (the @core path mapping is because of this).
  • My jest tests are located in test folder as you can also see in the configuration,

@samhh
Copy link
Owner

samhh commented May 5, 2022

Is this the issue perhaps?: #89

@incetarik
Copy link
Author

#89

Seems so yeah

@samhh samhh closed this as completed May 7, 2022
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