Skip to content

In JS, object is treated as 'any' #25624

Open

Description

TypeScript Version: 3.0.0-dev.20180711

Code

/** @typedef {object} T */
/** @type {T} */
const x = 0;

Expected behavior:

Error at x: 0 is not an object.

Actual behavior:

No error.

Activity

  1. ghost added
    BugA bug in TypeScript
    on Jul 13, 2018
  2. ghost added
    Domain: JSDocRelates to JSDoc parsing and type generation
    on Jul 13, 2018
  3. ghost added
    checkJsRelates to checking JavaScript using TypeScript
    on Jul 13, 2018
  4. ghost removed on Jul 13, 2018
  5. sandersn commented on Jul 16, 2018

    @sandersn
    Member

    I think this is a result of Object/object being treated as any. For example, /** @typedef {{}} T */ produces an error.

  6. sandersn commented on Jul 16, 2018

    @sandersn
    Member

    In getTypeFromTypeNode, we have:

    case SyntaxKind.ObjectKeyword:
        return node.flags & NodeFlags.JavaScriptFile ? anyType : nonPrimitiveType

    This was originally added in #17082. We could revisit this decision, but case-insensitive primitives and Object as any are good decisions in my opinion.

  7. changed the title [-]@typedef with no properties treated as 'any'[/-] [+]In JS, `object` is treated as 'any'[/+] on Jul 16, 2018
  8. 18 remaining items

  9. added
    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this feature
    and removed on Jul 26, 2019
  10. thorn0 commented on Feb 21, 2020

    @thorn0

    can be closed as fixed by #35661 ?

  11. sandersn commented on Feb 21, 2020

    @sandersn
    Member

    Maybe. #35661 only applies when noImplicitAny: true though.

  12. ExE-Boss commented on Feb 21, 2020

    @ExE-Boss
    Contributor

    I’d like if there was a way to use the object type in JSDoc without needing to enable noImplicitAny.

  13. sandersn commented on Feb 21, 2020

    @sandersn
    Member

    ExE Boss (@ExE-Boss) you can use the type NonPrimitive = object in one of your own d.ts files. Unfortunately, lots of existing JS code uses object to mean any or unknown, even projects like webpack that compile regularly with typescript.

  14. ExE-Boss commented on Feb 16, 2021

    @ExE-Boss
    Contributor

    Nathan Shively-Sanders (@sandersn) I’ve personally been using:

    /** @typedef {(typeof Object.create) extends (arg0: infer T, ...args: any) => any
    	? (T extends null | undefined ? never : T) : never} obj */

    Which is the inlined form of:

    /** @typedef {NonNullable<Parameters<typeof Object.create>[0]>} obj */
  15. DanielRosenwasser commented on May 5, 2026

    @DanielRosenwasser
    Member

    Keywords: object non-primitive non primitve nonprimitive jsdoc

  16. DanielRosenwasser commented on May 5, 2026

    @DanielRosenwasser
    Member

    Looks like TypeScript 7 might end up actually doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: JSDocRelates to JSDoc parsing and type generationDomain: JavaScriptThe issue relates to JavaScript specificallySuggestionAn idea for TypeScriptcheckJsRelates to checking JavaScript using TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions