Skip to content

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

@geogeim

Description

@geogeim

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:
DefinitelyTyped/DefinitelyTyped#33357

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions