[Feature request] allow use `as const` + `type` or `interface`
See original GitHub issueSearch 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:24
- Comments:18 (8 by maintainers)
Top Results From Across the Web
const assertions are the killer new TypeScript feature
The const keyword ensures that no reassignment to the variable can happen and a strict type of only that literal is guaranteed. But...
Read more >Typescript type check in switch statement, feature request or ...
I could solve this with: const newStringObj: AnyStringObj = { text: f1(stringObj) as string };. My question ...
Read more >Documentation - TypeScript 3.4
Notice the above needed no type annotations. The const assertion allowed TypeScript to take the most specific type of the expression. This can...
Read more >Effective Go - The Go Programming Language
Values; Interfaces and other types: Interfaces: Conversions: Interface ... With Go we take an unusual approach and let the machine take care of...
Read more >What's new in C# 11 - C# Guide | Microsoft Learn
Get an overview of the new features coming in C# 11. ... This change allows types that implement generic math interfaces to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe he wants to use the
as const
feature while still type checking that the structure matches an interface. A workaround I’d use for something like that would beThis StackOverflow question can be solved with this, https://stackoverflow.com/questions/57069802/as-const-is-ignored-when-there-is-a-type-definition