Comments (7)
That's kind of what I figured, but I thought I'd give it a shot anyway. At least to get some thought in this direction. Hopefully at least the readers can see the value in what this could provide in terms of type safety, hopefully one day have an official body backing something like this.
from typescript.
How is this different from #57943 and/or #13219?
from typescript.
It's different from both of those because I'm not suggesting to make any changes whatsoever to the type system. My proposal simply about supplying type maps that conform to web standards so that developers can use them how they like. It's a benign addition that would just mean people who are building result-like error handling libraries can leverage a strong and trusted up-to-date backbone for reference purposes - getting potential error types given a certain type. One use case would be that it would allow type-safe libraries to create convenient proxies around web apis.
Example, typescript would supply something like this:
/**
* Supplies an error map for a {@link ParentNode} instance
*/
type ParentNodeErrorMap = {
querySelector: SyntaxError
// ... all other errors
}
And then developers can build on top of those to create their own type systems, proxies, etc.
from typescript.
I don't understand what the request on the TypeScript side is. "error map" is not a term I'm familiar with and it doesn't really turn up any search results.
from typescript.
"Error map" is just the closest way to describe what I'm trying to put forward. It's simply a utility to map a type to its associated potential error according to w3c spec. I don't have the expertise to come up with the best way to do this. All I know it requires combing through the entire w3c spec and somehow including the potential errors in some fashion that they can accessed somehow.
Example:
Section 6.4 in the selector api specifies:
If result is invalid ([SELECT], section 12), raise a SYNTAX_ERR exception ([DOM-LEVEL-3-CORE], section 1.4) and abort this algorithm.
It would be great to have a way that this error information is somehow available in typescript. This would not affecting the typing system in any way.
I was thinking of literally the simplest way, which is likely not the best way, where typescript would supply a kind of global W3CErrorMap
, and a developer can go:
type querySelectorErrors = W3CErrorMap<document>['querySelector'] // would be the type of the error associated with SYNTAX_ERR
I foresee the development of type-safe proxies for standard apis.
from typescript.
If it's not going to affect the type system in some way, it can be an out-of-band artifact that people use if they are doing this kind of thing. Expanding the scope of our project to further cover investigating all the various W3C specs to produce that document doesn't seem to be something that TS is uniquely positioned to provide.
from typescript.
This issue has been marked as "Out of Scope" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- Union argument type with and spread operator
- Reuse original type nodes even when part of the node is not usable
- ts.createSourceFile trims leading newlines, causing stored line numbers to mismatch HOT 4
- Narrowing by type predicate fails to produce intersection type with weak type
- at the class getter property,why is need it initialize, if not then report error code is ts(2739) HOT 2
- Bloomberg TS5.5-beta feedback HOT 1
- Conditional Type Inference Bug in TS 5.x
- Protected instance member inaccessible to same-class constructor via object destructuring assignment HOT 2
- [ERROR] 15:13:55 Error: Cannot set headers after they are sent to the client HOT 3
- Isolated declarations does not handle object getters and setters with different types HOT 5
- TypeScript does not support bigint literals in type literal keys HOT 1
- Isolated declarations uses type information when emitting computed object keys HOT 5
- Error: Debug Failure when importing `AssertionError` from `node:assert/strict` HOT 4
- transpileDeclaration - Errors on unresolvable globals HOT 2
- duplicate comments on decorated fields
- Type narrowing with union types create impossible case with else statement HOT 6
- Error when using `import()` type within JSDoc tag `@implements`
- Narrowring a readonly class with instanceof of does not work on the else branch HOT 1
- Disposables disposed of, even though they are passed to a wrapper and still in use HOT 3
- It's the JSON validator that complains here. HOT 3
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.