Skip to content

ts will try to compile import files from a folder without reference or includeΒ #61440

@HolgerJeromin

Description

@HolgerJeromin

πŸ”Ž Search Terms

module import declaration

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried 3.3 and 5.9-nightly

⏯ Playground Link

https://github.com/HolgerJeromin/reproducible-examples/tree/ts-61440

πŸ’» Code

Folder jsModule with tsconfig and one module file:

file jsModule/jsModule.ts

export class TreeView {
  constructor() {
    Promise.allSettled([]);
  }
}

jsModule/tsconfig.json

{
  "compilerOptions": {
    "composite": true,
    "module": "ES2020",
    "target": "ES2015",
    "lib": ["DOM", "ES2015", "ES2020"],
    "strict": true
  },
  "files": ["jsModule.ts"]
}

And a folder src:

file src/main.ts

import { TreeView } from "../jsModule/jsModule.js";
const _TreeView = new TreeView();

src/tsconfig.json

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "module": "ES2022",
    "target": "ES2022",
    "lib": ["ES2015", "DOM"],
    "types": [],

    "strict": true
  },
  "files": ["main.ts"]
}

Note: No ES2020 lib.

πŸ™ Actual behavior

Build jsModule folder:

.\node_modules\.bin\tsc.cmd --build  .\jsModule\ --verbose

Results in emit of correct jsModule/jsModule.js and .d.ts file.
Build src folder:

.\node_modules\.bin\tsc.cmd --build  .\src\ --verbose

fails to compile because it uses not the correct tsconfig:

.\node_modules\.bin\tsc.cmd --build  .\src\ --verbose  --explainFiles
[16:15:17] Projects in this build: 
    * src/tsconfig.json

[16:15:17] Project 'src/tsconfig.json' is out of date because buildinfo file 'src/tsconfig.tsbuildinfo' indicates that program needs to report errors.

[16:15:17] Building project '/ts-issues/src/tsconfig.json'...

jsModule/jsModule.ts:3:13 - error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.

3     Promise.allSettled([])
              ~~~~~~~~~~

node_modules/typescript/lib/lib.es5.d.ts
  Library referenced via 'es5' from file 'node_modules/typescript/lib/lib.es2015.d.ts'
node_modules/typescript/lib/lib.es2015.d.ts
  [...]
node_modules/typescript/lib/lib.decorators.d.ts
  Library referenced via 'decorators' from file 'node_modules/typescript/lib/lib.es5.d.ts'
node_modules/typescript/lib/lib.decorators.legacy.d.ts
  Library referenced via 'decorators.legacy' from file 'node_modules/typescript/lib/lib.es5.d.ts'
jsModule/jsModule.ts
  Imported via "../jsModule/jsModule.js" from file 'src/main.ts'
src/main.ts
  Part of 'files' list in tsconfig.json

Found 1 error.

πŸ™‚ Expected behavior

The build failure is surprising.
Expected would be one of

  • The files are not included (or referenced) in src/tsconfig.json so they should not be rebuild (but only .d.ts files consumed) or
  • if this needs to be rebuild it should be correctly based on its tsconfig.json

Additional information about the issue

With my real code these folders are different VS 2022 projects and therefore have no references.
Instead I have many different tsconfig.json files for the esm files. So wildly importing some ts files into the compile will never get a reasonable output. (but break the output js files in imported folder).

Found #15272 but we had no references back in 2017.
Perhaps is this a simplified version of #58353

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions