Reputation: 1685
today I made a new React Native app and noticed something different than the last time I created a native app.
type Props = {}
export default class App extends Component<Props> {}
What type Props = {};
is?
I can't really find anything about it.
Upvotes: 10
Views: 10402
Reputation: 21
In TypeScript, there are a lot of basic types, such as string, boolean, and number.
Also, in TypeScript, there are advanced types and in these advanced types, there is something called type aliases.
With type aliases, you can create a new name for an existing type, any valid TypeScript type but you can't define a new type.
For example you can use the type alias chars for the string type:
type chars = string;
let messsage: chars; // same as string type
Or the type alias Props as an object:
type Props = {
src: string
alt: string
}
export default function Image({src, alt}: Props) {
return (
<img alt={alt} src={src}/>
)
}
Upvotes: 2