[react-native] - StyleSheet.create parameter properly constrained

Added test based on output of react-native init command
This commit is contained in:
Daniel Earwicker
2017-02-27 20:28:56 +00:00
parent 14f8fb1b17
commit a56d17157a
3 changed files with 52 additions and 2 deletions

View File

@@ -4558,10 +4558,14 @@ export namespace StyleSheet {
type Style = ViewStyle | TextStyle | ImageStyle
type NamedStyles<T> = {
[P in keyof T]: Style;
}
/**
* Creates a StyleSheet style reference from the given object.
*/
export function create<T>( styles: T ): T;
export function create<T extends NamedStyles<T>>( styles: T ): T;
/**
* Flattens an array of style objects, into one aggregated style object.

View File

@@ -0,0 +1,45 @@
import * as React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class AwesomeProject extends React.Component<{}, {}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

View File

@@ -20,6 +20,7 @@
"files": [
"index.d.ts",
"test/index.tsx",
"test/animated.tsx"
"test/animated.tsx",
"test/init-example.tsx"
]
}