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

feat: downlevel type in index signatures #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidyuk
Copy link

No description provided.

```ts
type O = { [key: string]: A };
```

Copy link
Owner

Choose a reason for hiding this comment

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

Please add a Semantics section. Specifically, the transformation as written makes sense for cases where

  1. the type is a template literal
  2. the type is reference to a template literal
    because x${number}y -> string (for example) is more permissive.

I'm not sure it makes sense for the following types that also work in 4.4:

  1. symbol
  2. a reference to symbol
  3. unions of string, symbol, number or template literals.
  4. a reference to unions of string, symbol, number or template literals.

cases (2), (4) and (6) are syntactically ambiguous, so I don't think they can be downlevelled with this tool.
(3) can't be downlevelled at all.
(5) can be downlevelled to multiple index signatures if the symbol isn't in the union.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated it to satisfy only the first case.

Regarding making it compatible with the second case, can we add a flag for "unsafe" transformations or allow transformations provided by user?

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.

2 participants