Skip to content

Object mapping string to boolean or Object gets typed instead to any with new JS->declaration support #34914

Closed

Description

C:\T\tsrc>npm ls
C:\T\tsrc
`-- typescript@3.7.1-rc


C:\T\tsrc>type example2.js
"use strict";

/**
 * Map of string to boolean or Object.
 *
 * @typedef {Object.<string, boolean | Object>} MyMap
 */

C:\T\tsrc>node_modules\.bin\tsc --allowjs --declaration --outdir out example2.js

C:\T\tsrc>type out\example2.d.ts
/**
 * Map of string to boolean or Object.
 */
type MyMap = {
    [x: string]: any;
};

C:\T\tsrc>

Activity

  1. RyanCavanaugh commented on Nov 8, 2019

    @RyanCavanaugh
    Member

    Object is an alias for any unless noImplicitAny is on. I believe Nathan Shively-Sanders (@sandersn) offered up some other workarounds offline?

    We should try making object be object in JS Doc now that we have a real object primitive type

  2. sandersn commented on Jan 10, 2020

    @sandersn
    Member

    This is something we ask periodically. When I recently removed the object=any rewrite when noImplicitAny is on, I found that webpack, in particular, still relies on it, despite checking their code with typescript. I expect the results would be similar for Object=any.

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

Metadata

Metadata

Labels

Experimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions