Activate Strict Null Checks

Set strictNullChecks to true
Make geometry and property nullable
Add tests
This commit is contained in:
denis
2018-02-27 23:21:24 +01:00
parent 39d94c080d
commit 9db7bc6088
3 changed files with 79 additions and 5 deletions
+74
View File
@@ -248,3 +248,77 @@ const typedPropertiesFeatureCollection: FeatureCollection<Point> = {
type: "FeatureCollection",
features: [typedPropertiesFeature]
};
// Strict Null Checks
let isNull: null;
let isPoint: Point;
let isPointOrNull: Point | null;
let isProperty: TestProperty;
let isPropertyOrNull: TestProperty | null;
const featureAllNull: Feature<null, null> = {
type: "Feature",
properties: null,
geometry: null
};
const featurePropertyNull: Feature<Point, null> = {
type: "Feature",
properties: null,
geometry: point
};
const featureGeometryNull: Feature<null, TestProperty> = {
type: "Feature",
properties: testProps,
geometry: null
};
const featureNoNull: Feature<Point, TestProperty> = {
type: "Feature",
properties: testProps,
geometry: point
};
const collectionAllNull: FeatureCollection<null, null> = {
type: "FeatureCollection",
features: [featureAllNull],
};
const collectionMaybeNull: FeatureCollection<Point | null, TestProperty | null> = {
type: "FeatureCollection",
features: [featureAllNull, featurePropertyNull, featureGeometryNull, featureNoNull],
};
const collectionPropertyMaybeNull: FeatureCollection<Point, TestProperty | null> = {
type: "FeatureCollection",
features: [featurePropertyNull, featureNoNull],
};
const collectionGeometryMaybeNull: FeatureCollection<Point | null, TestProperty> = {
type: "FeatureCollection",
features: [featureGeometryNull, featureNoNull],
};
const collectionNoNull: FeatureCollection<Point, TestProperty> = {
type: "FeatureCollection",
features: [featureNoNull],
};
isNull = featureAllNull.geometry;
isPoint = featurePropertyNull.geometry;
isNull = featureAllNull.properties;
isProperty = featureGeometryNull.properties;
isNull = collectionAllNull.features[0].geometry;
isPointOrNull = collectionMaybeNull.features[0].geometry;
isPoint = collectionPropertyMaybeNull.features[0].geometry;
isPointOrNull = collectionGeometryMaybeNull.features[0].geometry;
isPoint = collectionNoNull.features[0].geometry;
isNull = collectionAllNull.features[0].properties;
isPropertyOrNull = collectionMaybeNull.features[0].properties;
isPropertyOrNull = collectionPropertyMaybeNull.features[0].properties;
isProperty = collectionGeometryMaybeNull.features[0].properties;
isProperty = collectionNoNull.features[0].properties;
+4 -4
View File
@@ -139,12 +139,12 @@ export type GeoJsonProperties = { [name: string]: any; } | null;
* A feature object which contains a geometry and associated properties.
* https://tools.ietf.org/html/rfc7946#section-3.2
*/
export interface Feature<G extends GeometryObject, P = GeoJsonProperties> extends GeoJsonObject {
export interface Feature<G extends GeometryObject | null, P = GeoJsonProperties> extends GeoJsonObject {
type: "Feature";
/**
* The feature's geometry
*/
geometry: G | null;
geometry: G;
/**
* A value that uniquely identifies this feature in a
* https://tools.ietf.org/html/rfc7946#section-3.2.
@@ -153,14 +153,14 @@ export interface Feature<G extends GeometryObject, P = GeoJsonProperties> extend
/**
* Properties associated with this feature.
*/
properties: P | null;
properties: P;
}
/**
* A collection of feature objects.
* https://tools.ietf.org/html/rfc7946#section-3.3
*/
export interface FeatureCollection<G extends GeometryObject, P = GeoJsonProperties> extends GeoJsonObject {
export interface FeatureCollection<G extends GeometryObject | null, P = GeoJsonProperties | null> extends GeoJsonObject {
type: "FeatureCollection";
features: Array<Feature<G, P>>;
}
+1 -1
View File
@@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [