microsoft / microsoft/TypeScript
Better types for UrlSearchParams
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Suggestion
🔍 Search Terms
Restrictive typing on UrlSearchParams
✅ 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
declare var URLSearchParams: {
prototype: URLSearchParams;
// new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
new(init?:
| string
| URLSearchParams
| Record<string | number, string | number | boolean | string[] | number[] | boolean[]>
| [string | number | boolean, string | number | boolean | string[] | number[] | boolean[]][]): URLSearchParams;
toString(): string;
};
📃 Motivating Example
The actual typing design is more restrictive than the Javascript runtime itself.
💻 Use Cases
More possibilities to create strict typed UrlSearchParams objects:
let url = 'https://developer.microsoft.com'
const queryParams = new UrlSearchParams({
key1: ["v1", "v2"],
key2: ["v1", "v2", "v3"]
})
url = url + '?' + queryParams // https://developer.microsoft.com?key1=v1,v2&key2=v1,v2,v3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando la dichiarazione di URLSearchParams nella libreria standard e verifica la tipizzazione del relativo costruttore rispetto all’overload proposto e agli esempi motivanti. Esamina le definizioni dei tipi circostanti e i test dei tipi pertinenti prima di decidere quali forme di input supportare; il lavoro è completato quando le dichiarazioni accettano le forme più restrittive previste senza modificare il JavaScript emesso o il comportamento a runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- api, web-dev
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100