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

Inconsistent error messages caused by different tsconfig.json #60911

Closed
Roise-yue opened this issue Jan 4, 2025 · 2 comments
Closed

Inconsistent error messages caused by different tsconfig.json #60911

Roise-yue opened this issue Jan 4, 2025 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Roise-yue
Copy link

πŸ”Ž Search Terms

"inconsistent error massage", "tsconfig"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried (from v5.4 to v5.7)

⏯ Playground Link

No response

πŸ’» Code

import generate from "@babel/generator" ; 
import * as t from "@babel/types" ; 
import * as t from "@babel/types" ; 
const code = "class Example {}" ; 
declare const ast : t . Node ; 
ast . type ; 
null const output = generate ( ast , { } , code ) ; 
const result = generate ( ast , { retainLines : false , compact : "auto" , concise : false , jsescOption : { quotes : "double" , } , jsonCompatibleStrings : true , } , code , ) ; 
result . code ; 
result . map ; 

πŸ™ Actual behavior

The TS code above should have two kinds of syntax errors :

Duplicate identifier 't'.(line 2-3)
';' expected.(line 7)

I compiled this code separately using version 5.7 of tsc(The same applies to other versions as well) and found that when I used the "tsc file. ts" command, the first error was not reported. At this point, I used tsc -- showConfig and found that the default configuration file was being used, with the following configuration:

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "classic",
        "forceConsistentCasingInFileNames": true,
        "lib": [
            "es2023",
            "dom"
        ],
        "noEmitOnError": true,
        "strict": true,
        "jsx": "react",
        "declaration": true,
        "esModuleInterop": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "noImplicitReturns": true,
        "isolatedModules": true,
        "allowSyntheticDefaultImports": true,
        "preserveConstEnums": true,
        "useDefineForClassFields": true,
        "strictBuiltinIteratorReturn": true,
        "useUnknownInCatchVariables": true
    },
    "files": [
        "./1.ts"
    ],
    "include": [
        "1.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

However, in fact, the tsconfig.json I configured in the root directory is as follows:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "esnext",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2023","dom"],
    "noEmitOnError":true,
    "strict":true,
    "jsx": "react",
    "declaration": true,
    "esModuleInterop": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noImplicitReturns": true,
    "isolatedModules": true
  },
  "include": [
    "1.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

When I add "include:" file. ts "to tsconfig. json and use the tsc -- project tsconfig. json command to execute file. ts, TSC can report all syntax errors completely.
I have tried to modify the compilation options in the configuration file (for example, strict, moduleresolution), but I found that no matter how you modify the compilation options, the results are the same: use playground and TSC -- project tsconfig JSON can get complete error information by executing the code in these two ways, while the command using tsc+filename will not report the syntax error of "duplicate identifier".

I wonder if this inconsistency is due to the way I execute the program. However, I personally believe that the report of syntax errors should not be related to this.

πŸ™‚ Expected behavior

The error message of TSC should be consistent using different execution methods.

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

when I used the "tsc file. ts" command, the first error was not reported. At this point, I used tsc -- showConfig and found that the default configuration file was being used, with the following configuration:

This is working as intended and documented. When you provide a list of filenames to compile, then your local tsconfig is not used.

See https://www.typescriptlang.org/docs/handbook/compiler-options.html:

When input files are specified on the command line, tsconfig.json files are ignored.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 6, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants