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

[ID] --isolatedDeclarations disallows const initialized with a regex literal #58383

Open
6 tasks done
Conaclos opened this issue May 1, 2024 · 4 comments
Open
6 tasks done
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@Conaclos
Copy link

Conaclos commented May 1, 2024

πŸ” Search Terms

  • isolatedDeclarations
  • isolated declaration

βœ… Viability Checklist

⭐ Suggestion

I an unsure if it is a bug or a feature request...

An exported const without type annotation and initialized with a regex literal triggers the following error error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. in isolated declaration mode.

If I understand correctly, isolated declaration should allow unannotated const initialized with any literal?

πŸ“ƒ Motivating Example

See an example on the playground.

πŸ’» Use Cases

This could avoid a trivial type annotation.

@Conaclos Conaclos changed the title --isolatedDeclarations [ID} --isolatedDeclarations don't alow const initialized with a regex literal May 1, 2024
@Conaclos Conaclos changed the title [ID} --isolatedDeclarations don't alow const initialized with a regex literal [ID} --isolatedDeclarations disallows const initialized with a regex literal May 1, 2024
@Conaclos Conaclos changed the title [ID} --isolatedDeclarations disallows const initialized with a regex literal [ID] --isolatedDeclarations disallows const initialized with a regex literal May 1, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 1, 2024
@jakebailey
Copy link
Member

jakebailey commented May 1, 2024

This would require us to hardcode the type of a regex expression, no? Since regexes aren't an intrinsic and aren't valid initializers in dts?

I guess it could always just be RegExp, so long as that type name hasn't been reused. It's not like "number" or a literal value where the type name is reserved.

@RyanCavanaugh
Copy link
Member

This seems like the same situation as any other literal type, except that regex literal types don't exist, so we can safely write X: RegExp (yeah, barring shadowing)

@jakebailey
Copy link
Member

Just hope we never add stricter RegExp types...

Does the quick fix at least suggest adding : RegExp in the latest nightly?

@jakebailey
Copy link
Member

The fix does work, so this issue is mainly about whether or not ID should allow this inference.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants