microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.74k stars 12.46k forks source link

Extract the attribute value of type #40300

Closed lgf196 closed 4 years ago

lgf196 commented 4 years ago

Like interface props { title:string; type:'small' |'middle' |'default' } How can I get the value of type in the props interface?

j-oliveras commented 4 years ago

Something like:

interface props {
title:string;
type:'small' |'middle' |'default'
}

type allTypes = props["type"];

Playground.

RyanCavanaugh commented 4 years ago

It looks like this is a question rather than a bug report. This issue tracker is for tracking bugs and active work on TypeScript itself, rather than a general forum for programmers using TypeScript to get help or ask questions.

You can ask questions on sites like Stack Overflow. We are not able to provide one-on-one support on the issue tracker. Please read the issue template carefully - it has important information on what kinds of reports can be acted on here, as well as links to useful TypeScript resources. Thanks!

typescript-bot commented 4 years ago

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.