Skip to content

Allow to combine object shorthand notation with type assertion #53231

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

Closed
5 tasks done
danielrentz opened this issue Mar 13, 2023 · 3 comments
Closed
5 tasks done

Allow to combine object shorthand notation with type assertion #53231

danielrentz opened this issue Mar 13, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@danielrentz
Copy link

Suggestion

πŸ” Search Terms

object shorthand notation type assertion

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow to combine object shorthand notation with type conversions.

πŸ“ƒ Motivating Example

Using external libraries that are not typed very well.

function myFunc(type: string, data: unknown) {
  if (someExternalFunction(data)) {
    // here it's known that `data` is a string
    someOtherFunction({ type, data: data as string });
  }
}

It would be nice to be able to shorten this to

    someOtherFunction({ type, data as string });

or

    someOtherFunction({ type, <string>data });

πŸ’» Use Cases

Just to make source code more concise.

@MartinJohns
Copy link
Contributor

Last time this suggestion was closed due to lack of feedback and a comment to stay "well-clear of this syntactic space": #13035 (comment)

I think we want to stay well-clear of this syntactic space to keep room for future TC39.

@danielrentz
Copy link
Author

Ok... The issue search function did not bring that thing up. (as usual when I try to use the search :) )

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Mar 15, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants