GithubHelp home page GithubHelp logo

Comments (5)

sandersn avatar sandersn commented on June 21, 2024 2

The comment was left over from the original repro, because the original author wanted object | null to mean object, even with noImplicitAny: false.

from typescript.

fatcerberus avatar fatcerberus commented on June 21, 2024

Expected and Actual are swapped, I think?

from typescript.

sandersn avatar sandersn commented on June 21, 2024

No, it's the right way round. object becomes any when noImplicitAny: false, and signature quickinfo should reflect that.

from typescript.

Andarist avatar Andarist commented on June 21, 2024

So this runs into an existing weird situation with reusing existing type declaration. It's not even unique to JSDoc types.

type /*1*/O = {
    /*2*/foo: any | string
}

At marker 1 we can see:

type O = {
    foo: any | string;
}

but at marker 2 we can see:

(property) foo: any

Note that declaration emit preserves any | string here even in 5.4.

The reason why the type for @param gets printed as any is that it's the computed symbol's type that gets printed. When we hover over the function's symbol we end up serializing that symbol using serializeTypeForDeclaration (called by symbolToParameterDeclaration) and that prefers reusing the existing type node.

It's enough to wrap the type in this original repro into an object to get consistent non-reduced results:

/**
 * @param {{prop: object | null}} o
 */
function create2(o) {}

create2/*1*/(undefined);

With the above, { prop: object | null; } gets printed consistently. But that consistent result is misleading since the user won't easily notice that it's an any in disguise.

from typescript.

fatcerberus avatar fatcerberus commented on June 21, 2024

@sandersn In that case, it’s not true that create(undefined) “should error”. That’s why I asked. 😉

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.