microsoft / microsoft/TypeScript

tsc gets confused after assigning to module.exports - Property 'filename' does not exist on type

Offen
#30,088 1 Kommentar 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

@sandersn arbeitet bereits daran.

Seit 27.2.2019.

Needs Investigation
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

TypeScript Version: 3.4.0-dev.20190223

Search Terms:
module.filename
require.main === module
Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
module.exports = function(){ 
  return module.filename;
} 

Expected behavior:
Should not emit any error
Actual behavior:

D:\test>node_modules\.bin\tsc -v
Version 3.4.0-dev.20190223

D:\test>node_modules\.bin\tsc
test.js:2:17 - error TS2339: Property 'filename' does not exist on type '{ "D:/test/test": () => any; }'.

2   return module.filename;
                  ~~~~~~~~


Found 1 error.

Playground Link:
tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "checkJs": true,
    "allowJs": true,
    "resolveJsonModule": true, 
    "module": "commonjs",
    "lib": ["es2018"],
    "target": "es2018",
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "../*"
      ],
      "#/*": [
        "./*"
      ]
    },
    "types": [
      "node"
    ],
  },
  "exclude": [
    "node_modules",
    "public"
  ]
}

Related Issues:
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33357

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.