Skip to content

Object.defineProperty(variable) does not error in .js files if variable does not existΒ #61165

@eps1lon

Description

@eps1lon

πŸ”Ž Search Terms

defineProperty, cannot find namee

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about defineProperty

⏯ Playground Link

https://www.typescriptlang.org/play/?noImplicitAny=false&strictFunctionTypes=false&strictPropertyInitialization=false&strictBindCallApply=false&noImplicitThis=false&noImplicitReturns=false&alwaysStrict=false&declaration=false&target=3&module=1&filetype=js&strictNullChecks=false#code/PTAEAEBcGcFoGMAWBTeBrAUCUBhRBDAOwHNlQAiAGyOPNEgHsKAVATwAdkBleAJwEt2kOv0IsuuBoQBm-WqAZD+U6PSYBbfGjL9IoZL14NeGAPIAjAFapIAOgAmyWYWQAFI516RWACnPVEABoKQnx1ZHJggG8AN3xKAFdkAC5yR2l8BMphYIB3AUh8fxSMymhkAF8ASiA

πŸ’» Code

// javascript.js
// @ts-check
// Does not error unless in `.ts` file.
Object.defineProperty(foo, "name", { value: "default", writable: false });

πŸ™ Actual behavior

No error in .js files

πŸ™‚ Expected behavior

Errors in .js files with TS2304: Cannot find name 'foo'.

Additional information about the issue

Full repro: https://github.com/eps1lon/tsc-object-define-property

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions