Giter VIP home page Giter VIP logo

Comments (9)

loresorti avatar loresorti commented on June 7, 2024 1

SOS

from discord-api-types.

vladfrangu avatar vladfrangu commented on June 7, 2024

CNR
image

from discord-api-types.

vladfrangu avatar vladfrangu commented on June 7, 2024

Sike, I'm blind. I can repro, however this is not something that can be fixed without casts or typeguard methods :c
We'll probably add in more typeguards for situations like these

from discord-api-types.

suneettipirneni avatar suneettipirneni commented on June 7, 2024

You can only narrow one property at time. In the first condition of your if statement typescript sees you're trying to narrow the interaction, not the data type of that interaction, only the the first condition is taken into consideration since the other is another property.

Playground demo

from discord-api-types.

andre4ik3 avatar andre4ik3 commented on June 7, 2024

So how would I do it? I thought two separate if statements but that is weird and doesn't work anyway

CleanShot 2022-02-18 at 23 10 32@2x

from discord-api-types.

vladfrangu avatar vladfrangu commented on June 7, 2024

For now, either cast or wait till we implement typeguards 😅

from discord-api-types.

andre4ik3 avatar andre4ik3 commented on June 7, 2024

Ok.

from discord-api-types.

andre4ik3 avatar andre4ik3 commented on June 7, 2024

I was able to work around this issue by... creating my own framework based on discord-api-types that has classes around interactions with type guards lol.

I don't think there is anything possible for discord-api-types, as it's a type library, and type guards are functions that do checks at runtime, which would make interactions classes, which would take discord-api-types out of devDependencies and bloat compiled code...

So yeah, the only thing possible while keeping discord-api-types purely a typings library would be to cast. 😕

from discord-api-types.

andre4ik3 avatar andre4ik3 commented on June 7, 2024

Also interaction type guards just got merged in to 0.28.0 in utils, so I guess this is solved :)

from discord-api-types.

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.