Coder Social home page Coder Social logo

Comments (6)

estyrke avatar estyrke commented on July 17, 2024

I just verified - the error does not appear in TS 4.8.4, and it is still there in 4.9.5.

from pothos.

estyrke avatar estyrke commented on July 17, 2024

If I change the nullable to nullable: { items: true, list: false }, the error becomes (the possibly more clarifying)

error TS2322: Type '{ items: true; list: false; }' is not assignable to type '({ items: true; list: false; } & true) | ({ items: true; list: false; } & { items: boolean; list: boolean; } & true) | undefined'.
  Type '{ items: true; list: false; }' is not assignable to type '{ items: true; list: false; } & { items: boolean; list: boolean; } & true'.
    Type '{ items: true; list: false; }' is not assignable to type 'true'

from pothos.

hayes avatar hayes commented on July 17, 2024

I tried to reproduce this issue, but have not been able to:

https://stackblitz.com/edit/typescript-rmf22w?file=index.ts,tsconfig.json

This sees specific to types not included in the example above

from pothos.

estyrke avatar estyrke commented on July 17, 2024

Thanks for looking into it! After trying for quite a while to extend the stackblitz enough without succeeding, I finally realized that explicitly typing the return value of Group.children to string[] resolves the issue.

I'm a bit curious why the stackblitz differs from my code though. I tried

export class Group {
  get children(): ("a" | "b")[] {
    return ["a"]; //GROUP_DEFINITIONS[<GroupName>this.name];
  }
}

type Foo = ExposeNullableOption<
  PothosSchemaTypes.ExtendDefaultTypes<{}>,
  ["String"],
  Group,
  "children"
>;

In the "real" code (using VS code tooltips), Foo resolves to

type Foo = FieldNullability<["String"]> & (true | {
    items: boolean;
    list: true;
} | {
    items: boolean;
    list: true;
})

But in stackblitz it's

type Foo = FieldNullability<["String"]> & (boolean | {
    items: boolean;
    list: boolean;
} | {
    items: boolean;
    list: boolean;
})

I'm no typescript expert, but It seems like this could be a typescript bug.

type Bar = Group["children"] extends NonNullable<Group["children"]>
  ? true
  : false;

resolves to true in both my local editor and in stackblitz, which I think means that nullable should be allowed to be false.

from pothos.

hayes avatar hayes commented on July 17, 2024

Thanks for the detailed reply! Figured out the issue, and fixed it here: 3021b43

from pothos.

estyrke avatar estyrke commented on July 17, 2024

Works like a charm! Thanks for persisting!

from pothos.

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.