Skip to content

Commit

Permalink
Merge pull request #178 from frenic/fallback-readonly
Browse files Browse the repository at this point in the history
Add readonly for fallback values
  • Loading branch information
frenic authored Apr 14, 2023
2 parents 97ec3aa + 8deb073 commit 46694de
Show file tree
Hide file tree
Showing 35 changed files with 397 additions and 289 deletions.
12 changes: 12 additions & 0 deletions __tests__/__fixtures__/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ const cssWithFallbackValues: CSS.PropertiesFallback = {
clip: [undefined],
};

const cssWithFallbackConstValues: CSS.PropertiesFallback = {
flexGrow: [1] as const,
flexShrink: [1] as const,
flexBasis: ['max-content'] as const,
flexDirection: ['row'] as const,
MozAppearance: ['button'] as const,
msOverflowStyle: ['scrollbar'] as const,
height: undefined,
clip: [undefined] as const,
};

const cssWithHyphenProperties: CSS.PropertiesHyphen = {
'flex-grow': 1,
'flex-shrink': 0,
Expand Down Expand Up @@ -149,6 +160,7 @@ const differentMajorVersions: CSS.Properties = {} as OldCSS.Properties;

css;
cssWithFallbackValues;
cssWithFallbackConstValues;
cssWithHyphenProperties;
cssWithDifferentLength;
unknownProperty;
Expand Down
48 changes: 27 additions & 21 deletions __tests__/__snapshots__/dist.typescript-3.5.ts.snap
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Typescript 3.5 detects errors 1`] = `
"31:2 - Type 'undefined[]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | HyphenateCharacter[] | undefined'.
Type 'undefined[]' is not assignable to type 'HyphenateCharacter[]'.
"31:2 - Type 'undefined[]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | readonly HyphenateCharacter[] | undefined'.
Type 'undefined[]' is not assignable to type 'readonly HyphenateCharacter[]'.
Type 'undefined' is not assignable to type 'HyphenateCharacter'."
`;

exports[`Typescript 3.5 detects errors 2`] = `
"48:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {}), string & {}>'.
Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'Properties<0 | (string & {}), string & {}>'."
"42:2 - Type 'readonly [undefined]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | readonly HyphenateCharacter[] | undefined'.
Type 'readonly [undefined]' is not assignable to type 'readonly HyphenateCharacter[]'.
Type 'undefined' is not assignable to type 'HyphenateCharacter'."
`;

exports[`Typescript 3.5 detects errors 3`] = `
"52:2 - Type 'number[]' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
"59:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {}), string & {}>'.
Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'Properties<0 | (string & {}), string & {}>'."
`;

exports[`Typescript 3.5 detects errors 4`] = `
"53:2 - Type 'number[]' is not assignable to type '"inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | (number & {}) | undefined'.
"63:2 - Type 'number[]' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
`;

exports[`Typescript 3.5 detects errors 5`] = `
"58:6 - Type '{}' is not assignable to type 'string & {}'.
Type '{}' is not assignable to type 'string'."
"64:2 - Type 'number[]' is not assignable to type '"inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | (number & {}) | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
`;

exports[`Typescript 3.5 detects errors 6`] = `
"63:10 - Type 'Range' is not assignable to type '"auto"'.
"69:6 - Type '{}' is not assignable to type 'string & {}'.
Type '{}' is not assignable to type 'string'."
`;

exports[`Typescript 3.5 detects errors 7`] = `
"74:10 - Type 'Range' is not assignable to type '"auto"'.
Type 'string & {}' is not assignable to type '"auto"'."
`;

exports[`Typescript 3.5 detects errors 7`] = `"70:6 - Type '1' is not assignable to type 'string | 0'."`;
exports[`Typescript 3.5 detects errors 8`] = `"81:6 - Type '1' is not assignable to type 'string | 0'."`;

exports[`Typescript 3.5 detects errors 8`] = `"82:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;
exports[`Typescript 3.5 detects errors 9`] = `"93:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;

exports[`Typescript 3.5 detects errors 9`] = `"96:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;
exports[`Typescript 3.5 detects errors 10`] = `"107:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;

exports[`Typescript 3.5 detects errors 10`] = `"106:14 - Argument of type '1' is not assignable to parameter of type 'string | 0 | (string | 0)[]'."`;
exports[`Typescript 3.5 detects errors 11`] = `"117:14 - Argument of type '1' is not assignable to parameter of type 'string | 0 | (string | 0)[]'."`;

exports[`Typescript 3.5 detects errors 11`] = `
"107:14 - Argument of type '1[]' is not assignable to parameter of type 'string | 0 | (string | 0)[]'.
exports[`Typescript 3.5 detects errors 12`] = `
"118:14 - Argument of type '1[]' is not assignable to parameter of type 'string | 0 | (string | 0)[]'.
Type '1[]' is not assignable to type '(string | 0)[]'.
Type '1' is not assignable to type 'string | 0'."
`;

exports[`Typescript 3.5 detects errors 12`] = `"120:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;
exports[`Typescript 3.5 detects errors 13`] = `"131:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;

exports[`Typescript 3.5 detects errors 13`] = `"134:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;
exports[`Typescript 3.5 detects errors 14`] = `"145:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;

exports[`Typescript 3.5 detects errors 14`] = `"144:34 - Argument of type '1' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'."`;
exports[`Typescript 3.5 detects errors 15`] = `"155:34 - Argument of type '1' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'."`;

exports[`Typescript 3.5 detects errors 15`] = `
"145:34 - Argument of type '[1]' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'.
exports[`Typescript 3.5 detects errors 16`] = `
"156:34 - Argument of type '[1]' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'.
Type '[1]' is not assignable to type '[0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 5 more ... | "min-intrinsic"]'.
Type '1' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 5 more ... | "min-intrinsic"'."
`;
48 changes: 27 additions & 21 deletions __tests__/__snapshots__/dist.typescript-3.6.ts.snap
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Typescript 3.6 detects errors 1`] = `
"31:2 - Type 'undefined[]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | HyphenateCharacter[] | undefined'.
Type 'undefined[]' is not assignable to type 'HyphenateCharacter[]'.
"31:2 - Type 'undefined[]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | readonly HyphenateCharacter[] | undefined'.
Type 'undefined[]' is not assignable to type 'readonly HyphenateCharacter[]'.
Type 'undefined' is not assignable to type 'HyphenateCharacter'."
`;

exports[`Typescript 3.6 detects errors 2`] = `
"48:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {}), string & {}>'.
Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'Properties<0 | (string & {}), string & {}>'."
"42:2 - Type 'readonly [undefined]' is not assignable to type '"auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | readonly HyphenateCharacter[] | undefined'.
Type 'readonly [undefined]' is not assignable to type 'readonly HyphenateCharacter[]'.
Type 'undefined' is not assignable to type 'HyphenateCharacter'."
`;

exports[`Typescript 3.6 detects errors 3`] = `
"52:2 - Type 'number[]' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
"59:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {}), string & {}>'.
Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'Properties<0 | (string & {}), string & {}>'."
`;

exports[`Typescript 3.6 detects errors 4`] = `
"53:2 - Type 'number[]' is not assignable to type '"inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | (number & {}) | undefined'.
"63:2 - Type 'number[]' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
`;

exports[`Typescript 3.6 detects errors 5`] = `
"58:6 - Type '{}' is not assignable to type 'string & {}'.
Type '{}' is not assignable to type 'string'."
"64:2 - Type 'number[]' is not assignable to type '"inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | (number & {}) | undefined'.
Type 'number[]' is not assignable to type '"unset"'."
`;

exports[`Typescript 3.6 detects errors 6`] = `
"63:10 - Type 'Range' is not assignable to type '"auto"'.
"69:6 - Type '{}' is not assignable to type 'string & {}'.
Type '{}' is not assignable to type 'string'."
`;

exports[`Typescript 3.6 detects errors 7`] = `
"74:10 - Type 'Range' is not assignable to type '"auto"'.
Type 'string & {}' is not assignable to type '"auto"'."
`;

exports[`Typescript 3.6 detects errors 7`] = `"70:6 - Type '1' is not assignable to type 'string | 0'."`;
exports[`Typescript 3.6 detects errors 8`] = `"81:6 - Type '1' is not assignable to type 'string | 0'."`;

exports[`Typescript 3.6 detects errors 8`] = `"82:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;
exports[`Typescript 3.6 detects errors 9`] = `"93:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;

exports[`Typescript 3.6 detects errors 9`] = `"96:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;
exports[`Typescript 3.6 detects errors 10`] = `"107:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;

exports[`Typescript 3.6 detects errors 10`] = `"106:14 - Argument of type '1' is not assignable to parameter of type 'string | 0 | (string | 0)[]'."`;
exports[`Typescript 3.6 detects errors 11`] = `"117:14 - Argument of type '1' is not assignable to parameter of type 'string | 0 | (string | 0)[]'."`;

exports[`Typescript 3.6 detects errors 11`] = `
"107:14 - Argument of type '1[]' is not assignable to parameter of type 'string | 0 | (string | 0)[]'.
exports[`Typescript 3.6 detects errors 12`] = `
"118:14 - Argument of type '1[]' is not assignable to parameter of type 'string | 0 | (string | 0)[]'.
Type '1[]' is not assignable to type '(string | 0)[]'.
Type '1' is not assignable to type 'string | 0'."
`;

exports[`Typescript 3.6 detects errors 12`] = `"120:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;
exports[`Typescript 3.6 detects errors 13`] = `"131:23 - This condition will always return 'false' since the types 'string | 0 | (string | 0)[]' and '1' have no overlap."`;

exports[`Typescript 3.6 detects errors 13`] = `"134:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;
exports[`Typescript 3.6 detects errors 14`] = `"145:25 - This condition will always return 'false' since the types 'string | 0' and '1' have no overlap."`;

exports[`Typescript 3.6 detects errors 14`] = `"144:34 - Argument of type '1' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'."`;
exports[`Typescript 3.6 detects errors 15`] = `"155:34 - Argument of type '1' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'."`;

exports[`Typescript 3.6 detects errors 15`] = `
"145:34 - Argument of type '[1]' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'.
exports[`Typescript 3.6 detects errors 16`] = `
"156:34 - Argument of type '[1]' is not assignable to parameter of type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 6 more ... | [...]'.
Type '[1]' is not assignable to type '[0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 5 more ... | "min-intrinsic"]'.
Type '1' is not assignable to type '0 | "auto" | "inherit" | (string & {}) | "-moz-initial" | "initial" | "revert" | "revert-layer" | "unset" | "-moz-fit-content" | "-moz-max-content" | "-moz-min-content" | "fit-content" | ... 5 more ... | "min-intrinsic"'."
`;
Loading

0 comments on commit 46694de

Please sign in to comment.