Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string-case types #25

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

KajSzy
Copy link

@KajSzy KajSzy commented Feb 21, 2023

This solves #16

type Union = "a" | "b" | "c";

const foo: Union = "a";

const fooUpperCased: Uppercase<Union> = foo.toUpperCase(); // should be 'A' | 'B' | 'C'

src/tests/string-case.ts Outdated Show resolved Hide resolved
src/tests/string-case.ts Outdated Show resolved Hide resolved
Co-authored-by: Denis Zavershinskiy <zaverden@gmail.com>
Copy link

@helmturner helmturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of another language with upper- and lower-case letters to throw at it, but it's passing these tests (basically the same tests you wrote, but consolidated and made more exhaustive).

type EnglishLower = "abcdefghijklmnopqrstuvwxyz"
type EnglishUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
type CyrillicLower = "юабцдефгхийклмнопярстужвьызшэщчъ"
type CyrillicUpper = "ЮАБЦДЕФГХИЙКЛМНОПЯРСТУЖВЬЫЗШЭЩЧЪ"

doNotExecute(async () => {  
  doNotExecute(async () => {
    const englishUpperString = "" as EnglishUpper;
    const cyrillicUpperString = "" as CyrillicUpper;
  
    const englishLowerString = englishUpperString.toLowerCase();
    const cyrillicLowerString = cyrillicUpperString.toLowerCase();

    const englishLocaleLowerString = englishUpperString.toLocaleLowerCase();
    const cyrillicLocaleLowerString = cyrillicUpperString.toLocaleLowerCase();

    type tests = [
        Expect<Equal<typeof englishLowerString, EnglishLower>>,
        Expect<Equal<typeof cyrillicLowerString, CyrillicLower>>,
        Expect<Equal<typeof englishLocaleLowerString, EnglishLower>>,
        Expect<Equal<typeof cyrillicLocaleLowerString, CyrillicLower>>,

        Expect<NotEqual<typeof englishUpperString, typeof englishLowerString>>,
        Expect<NotEqual<typeof cyrillicUpperString, typeof cyrillicLowerString>>,
        Expect<NotEqual<typeof englishUpperString, typeof englishLocaleLowerString>>,
        Expect<NotEqual<typeof cyrillicUpperString, typeof cyrillicLocaleLowerString>>,
    ];
  });
});

  doNotExecute(async () => {
    const englishLowerString = "" as EnglishLower;
    const cyrillicLowerString = "" as CyrillicLower;
  
    const englishUpperString = englishLowerString.toUpperCase();
    const cyrillicUpperString = cyrillicLowerString.toUpperCase();

    const englishLocaleUpperString = englishLowerString.toLocaleUpperCase();
    const cyrillicLocaleUpperString = cyrillicLowerString.toLocaleUpperCase();

    type tests = [
        Expect<Equal<typeof englishUpperString, EnglishUpper>>,
        Expect<Equal<typeof cyrillicUpperString, CyrillicUpper>>,
        Expect<Equal<typeof englishLocaleUpperString, EnglishUpper>>,
        Expect<Equal<typeof cyrillicLocaleUpperString, CyrillicUpper>>,

        Expect<NotEqual<typeof englishLowerString, typeof englishUpperString>>,
        Expect<NotEqual<typeof cyrillicLowerString, typeof cyrillicUpperString>>,
        Expect<NotEqual<typeof englishLowerString, typeof englishLocaleUpperString>>,
        Expect<NotEqual<typeof cyrillicLowerString, typeof cyrillicLocaleUpperString>>,
    ];
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants