Comments (9)
This feature was designed around modifying property names, e.g. turning
type In = {
foo: string;
}
into
type Out = {
getFoo(): string;
}
or parsing short data like /foo/bar
-> ["foo", "bar"]
The fact that it even lets you try to do something with literals over 100 characters long was probably a huge mistake. I'd really, really ask that people not try to do this except as a learning exercise, and accept that you're absolutely going to encounter limitations. The editor performance you're going to see from this approaches is going to be uniformly terrible.
If people want to write a lisp interpreter in the type system string parser for fun that's fine, but it's not a mainline scenario and anything even close to it is going way past the design limits of what it's there for. It's like trying to use a kitchen knife as a wheel axle -- you might be able to make it work but it's not what it's there for and the knife manufacturer isn't going to document the bending modulus of it for you.
As such, we're not able to spend time investigating reports like this. That said, if you independently find and verify some fix, PRs would possibly be accepted.
from typescript.
@MartinJohns: We talked to @jakebailey about this, and just because this isn't recommended / accounted for in TypeScript’s type checker, to us, that doesn't mean that there aren't some valuable insights to be had here from discussing what we ran into ❤️
FWIW, we're planning to have a hybrid approach for codegen + in-typesystem parsing in the future to get around linear increases in parsing time, and even ignoring this, the project also has a lot of non-string-literal parsing insights, since we're dealing with large data sets.
For now though, the issue we ran into is that the string literal inferences we're using, which are done character by character, cause a performance cliff, where cost increases per character when we bail out of tail recursion (due to the max tail recursion limit), which is potentially related to allocations for each string literal type.
I'd say, no matter whether we're dealing with a DSL or not, that's potentially an indicator that per-character inference in literals could become more efficient with a fast path, if that's possible
from typescript.
I see that there's no interest for this, I made this issue to see if there was a possible collaboration. It is disappointing that it was met with this kind of rude commentary. If anything in this issue could have been seen as bad intent, I apologize. I acknowledge the size of the project and the amount of issues that come in, I was in no way shape or form requesting urgent help or whatever. I was merely suggesting that there's room for improvement and if anyone was up for that to point me in the right direction.
I suspect that issues like this one might arise in the future, as folks explore the boundaries of TypeScript more and more, heck the router-space doing string literal parsing might fall into that bucket soon enough (unless that's also a DSL...). You lot have created something to be proud of and I respect that you have clear boundaries in your project. A design philosophy will allow you to iterate on what matters to your project.
That being said, I suspect that when folks started building types on top of JavaScript there could have been similar reactions... Yet here we are, we got an amazing language that allows us to express complex types on top of JavaScript, maybe someday TypeScript will enable all of these wonderful features and enable us to be even more expressive and push the boundaries of static-types.
from typescript.
I apologize if any rudeness was perceived in that message; it was not my intent and I'll try to do better in the future.
I made this issue to see if there was a possible collaboration
I just want to reiterate that the door is totally open if other people want to optimize something in a way that doesn't incur other significant costs. We're not able to offer time to research optimization approaches, but if you do this and find something that works well, we can help you get it into a workable PR.
from typescript.
Just FYI, template strings are explicitly not suited/meant for parsing DSL.
"I want to write a full GraphQL parser and provide exact API shapes back"
This is a moderate 👎 - we think we'd be encouraging people to use the wrong tools to solve these problems
Related: #43335
from typescript.
Compiling the linked project completes in 4 seconds on my machine; is the problem strictly that you hit a limit? Can you provide an example that hits a limit or is slow?
from typescript.
It is disappointing that it was met with this kind of rude commentary.
I haven't seen any rude commentary.
from typescript.
I am not going to debate what is rude or not but the following comment, at least to me, comes across quite rude for an issue of this kind. It's not like this red-line is documented anywhere, I will however leave it at that.
It's like trying to use a kitchen knife as a wheel axle -- you might be able to make it work but it's not what it's there for and the knife manufacturer isn't going to document the bending modulus of it for you.
from typescript.
That was simply an analogy; any sarcastic or rude intent you read in it is on you.
It's not like this red-line is documented anywhere
FWIW, the documentation for the hypothetical knife probably wouldn't say anywhere "Don't use our product as a wheel axle." 😄 That said, GitHub issues are considered part of documentation, and template string inference not being intended for this use case is well-established by the maintainers here.
from typescript.
Related Issues (20)
- FinalizationRegistry.unregister should return boolean instead of void
- HTML/C-like #include statements HOT 10
- Incorrect automatically type infer HOT 2
- [NewErrors] 5.5.0-dev.20240324 vs 5.4.3 HOT 17
- [ServerErrors][TypeScript] 5.5.0-dev.20240324 HOT 7
- [ServerErrors][JavaScript] 5.5.0-dev.20240324 HOT 5
- Compilation fails with TS6059 under Windows 10 but passes under Windows 11 or Linux HOT 11
- Ts report a wrong comparison when a variable may be changed async. HOT 3
- LSP inserts duplicate `async` keyword HOT 4
- `String.startsWith`, `String.endsWith`, and `String.includes` should have type assertion for when search string is a string subtype HOT 2
- Replacement character (`\uFFFD`) in JavaScript/TypeScript causes to breaks HOT 19
- Why can't I declare a union of functions with different parameter types? HOT 3
- Applying class decorator affects valid ordering of class definitions (w/ emitDecoratorMetadata) HOT 2
- Always true/false condition makes typeguard fail HOT 4
- Support abstract class methods without abstract class HOT 1
- Support non-bool assertions HOT 1
- A Pragmatic, Not-Really-Typed Errors Proposal HOT 11
- Make switch exhaustiveness check as a configuration of tsc. HOT 1
- Cannot extend `XMLHttpRequest` when target is `ES5` HOT 2
- Type predicate not inferred for discriminated union?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.