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

0.24.0 Regression Test #164

Merged
merged 7 commits into from Sep 17, 2022
Merged

Conversation

tommy-mitchell
Copy link
Contributor

Refactors the parser as mentioned here in #161 and adds a regression test:

const tag = (strings: TemplateStringsArray, ...args: any[]) => {
  let value = strings[0];
  let i = 0;

  while (i < args.length) {
    let s: string;

    if (Array.isArray(args[i])) {
      // PROBLEM: Identifiers `map` and `join` have no Symbols
      // TS should infer `args[i]` as `Array<any>`, but doesn't
      // `checker.getSymbolAtLocation(expression)` is undefined
      s = args[i].map((x: any) => `${x}`).join(' ');
    } else {
      s = `${args[i]}`;
    }

    value += s;
  }

  return value;
};

// fails with `Cannot read properties of undefined (reading 'flags')` in 0.24.0
expectType<string>(tag`foo`);

(AST Viewer). Adapted from zx core.ts.

I'm not sure why tsd is parsing the source code of zx instead of just the test-d files. I wasn't able to reproduce this in a test case.

Having a Node but not a Symbol means that the given expression is syntactically-correct, but not semantically-correct. Ultimately, I was wrong to assume that maybeAlias would be non-null and it's safer to have this check.

@tommy-mitchell
Copy link
Contributor Author

Made the test simpler:

// Identifier `bar` has no Symbol
const anyCall = (foo: any) => foo.bar();

// Fails with `Cannot read properties of undefined (reading 'flags')` in 0.24.0
expectType<any>(anyCall('foo'));

@sindresorhus sindresorhus merged commit 09c0d17 into tsdjs:main Sep 17, 2022
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

2 participants