Giter Site home page Giter Site logo

Comments (5)

hitsthings avatar hitsthings commented on April 27, 2024 1

Ok fair enough. Thanks for the explanation!

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 27, 2024

Bisects to #46137

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 27, 2024

That PR adds this code

                        if (relation === comparableRelation) {
                            return templateLiteralTypesDefinitelyUnrelated(source as TemplateLiteralType, target as TemplateLiteralType) ? Ternary.False : Ternary.True;
                        }

where templateLiteralTypesDefinitelyUnrelated is currently conservatively defined as:

    function templateLiteralTypesDefinitelyUnrelated(source: TemplateLiteralType, target: TemplateLiteralType) {
        // Two template literal types with diffences in their starting or ending text spans are definitely unrelated.
        const sourceStart = source.texts[0];
        const targetStart = target.texts[0];
        const sourceEnd = source.texts[source.texts.length - 1];
        const targetEnd = target.texts[target.texts.length - 1];
        const startLen = Math.min(sourceStart.length, targetStart.length);
        const endLen = Math.min(sourceEnd.length, targetEnd.length);
        return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
            sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
    }

I'm not sure how much further we want to take this logic; allowing more things than is technically possible in the comparable relation isn't a very big defect, and it's somewhat hard to put exact bounds on what the toString of any number might be -- if we tighten up to say the first digit must be numeric or something, then there's still a "bug" where sequences like "00" aren't detected as being not-possible outputs of toString.

from typescript.

hitsthings avatar hitsthings commented on April 27, 2024

Is this area very performance-bound? I've been hashing it out and I think I could write something to relatively accurately compare two template strings for overlap, but it'd necessarily require checking a lot of different options. It would presumably take a lot more time than checking if the first and last parts are the same.
Is it worth the time for me to explore that?

This caused me to ship a bug so I'd like to fix it. Otherwise I have to use branded strings to distinguish my number strings from other strings which is kinda annoying.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 27, 2024

Overall codesize and complexity is a budget we have to manage. By far the most common complaint we get in this area is that "I should be able to compare anything"; we get very few "I was not allowed to compare two things that in reality didn't overlap". So I'd really need to see more feedback from other people on this before committing to consider any approach.

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.