mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
Activate Strict Null Checks
Set strictNullChecks to true Make geometry and property nullable Add tests
This commit is contained in:
@@ -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;
|
||||
|
||||
Vendored
+4
-4
@@ -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>>;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
|
||||
Reference in New Issue
Block a user