microsoft / microsoft/TypeScript

[Feature request] allow use `as const` + `type` or `interface`

Offen
#31,062 18 Kommentare 31 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

Suggestion

Use Cases

allow use as const + type or interface

so we can make sure as const is follow type or interface

Examples

check as const output is follow IVueCliPrompt[]

.ts

interface IVueCliPrompt
{
	name: string,
	type: 'confirm' | string,
	message: string,
	default: unknown
}

const prompts = [
	{
		name: 'replaceFiles',
		type: 'confirm',
		message: 'Replace current files with preset files?',
		default: false
	},
] as const IVueCliPrompt[];

export = prompts

.d.ts

declare const prompts: readonly [{
    readonly name: "replaceFiles";
    readonly type: "confirm";
    readonly message: "Replace current files with preset files?";
    readonly default: false;
}];
export = prompts;

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue enthält TypeScript-Beispiele zur Kombination von as const mit interface oder type und zeigt die erwartete .d.ts-Ausgabe. Es werden keine Quelldateien oder Tests genannt; beginne damit nachzuverfolgen, wie diese Konstrukte geparst und geprüft werden, und definiere anschließend das Verhalten von Syntax und Typsystem, bevor du die erzeugte Deklarationsausgabe validierst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.