what's the best way to get class Props all properties
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
I have the ts file like this:
```tsx
export interface DynamicProps, Data = any, Options extends Record = {}, DataRecord = Record> extends ControllerFieldState, Omit {
value: Data | null;
onChange: (data: Data | null) => void;
watchingDataRecord: {
[i in keyof DataRecord]: DataRecord[i] | null;
};
componentProps: CustomProps;
metadataDescriptors: {
getOutputDataDescriptor: () => Data extends Record ? {
[i in keyof Data]: string;
} : string;
getCustomValidator: (options: Options, value: Data) => string | boolean;
};
}
interface CustomProps {
placeholder: string;
helperText: string;
maxLength: number;
}
interface OutputData {
name?: string;
}
interface ValidatorOptions {
idCount: number;
}
interface WatchingDataRecord {
description: {
data: string;
locked: boolean;
};
}
type Props = DynamicComponentProps;
export default class Text extends React.Component {
}
```
and I want to get this React component Props all properties
```ts
const somethingTypeAlias = sourceFile.getTypeAliasOrThrow("Props");
const somethingType = somethingTypeAlias.getType();
for (const prop of properties)
console.log(prop.getEscapedName(), prop.getTypeAtLocation(somethingTypeAlias).getText());
```
Contributor guide
Research direction
Start with the getTypeAliasOrThrow("Props") and getType() entry points shown in the issue, then inspect how properties are obtained for aliases, generic instantiations, and inherited or intersected types. Confirm the supported way to enumerate every Props property and verify that each property's resolved type is reported correctly for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100