Skip to content

[Bug]: types not found when filename has certain words in it #4263

@sebpiq

Description

@sebpiq

Version

29.1.2

Steps to reproduce

To be honest, I am not sure where to start searching for that bug, it's so strange. So I'm starting here with ts-jest, as a best guess 🤷

  1. Create a tsts.js file exporting a function someFunc :
// src/tsts.js
const someFunc = (t) => t;

export { someFunc };

and its corresponding types tsts.d.ts :

// src/tsts.d.ts
export declare const someFunc: (t: number) => number;
  1. Create another file blo.ts which imports the function from tsts and uses it :
// src/blo.ts

import { someFunc } from './tsts'

export const useSomeFunc = (a: number) => someFunc(a) + 1

Create a test that uses :

// src/blo.test.ts

import assert from 'assert'
import { useSomeFunc } from './blo'

describe('blo', () => {
    it('should work', () => {
        assert.strictEqual(useSomeFunc(1), 2)
    })
})

Expected behavior

I expect the test to run and output :

 PASS  src/blo.test.ts
  blo
    ✓ should work (1 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.75 s
Ran all test suites.

Actual behavior

 FAIL  src/blo.test.ts
  ● Test suite failed to run

    src/tsts.js:1:19 - error TS7006: Parameter 't' implicitly has an 'any' type.

    1 const someFunc = (t) => t;
                        ~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.712 s
Ran all test suites.

Debug log

ts-jest.log

Additional context

Now's the interesting part : if I rename (and update imports) :

tsts.js -> bla.js
tsts.d.ts -> bla.d.ts

Everything works as expected.

On the other hand, I get the same bug if I rename like so :

tsts.js -> exports.js
tsts.d.ts -> exports.d.ts

Environment

System:
    OS: Linux 6.5 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx
Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
npmPackages:
    jest: ^29.4.3 => 29.7.0

Full project to reproduce the bug

full-project-reproduce-bug.zip

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions