Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JSON types #373

Merged
merged 1 commit into from
Mar 3, 2021
Merged

Improve JSON types #373

merged 1 commit into from
Mar 3, 2021

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Mar 3, 2021

The JSON types (Json and IsJsonable) have been improved:

  • The last part of the Json union type was redundant, and has been removed (Partial<Record<never, never>>).
  • A check has been added to IsJsonable to prevent the use of numeric keys in objects. In testing I've found this doesn't prevent all cases of this, but it does prevent some.

IsJsonable playground link with tests

Json playground link with tests

The JSON types (`Json` and `IsJsonable`) have been improved:

* The last part of the `Json` union type was redundant, and has been
removed (`Partial<Record<never, never>>`).
* A check has been added to `IsJsonable` to prevent the use of numeric
keys in objects. In testing I've found this doesn't prevent all cases
of this, but it does prevent some.

`IsJsonable` playground link with tests: https://www.typescriptlang.org/play?#code/C4TwDgpgBGBOCWBbex4DdoF4oDsCuANgQLABQUFUAPlAEYD29BEAhjmZdbnorRLB0o0AzsAQ4A5mTKhIUACIQAZvBwoIBEADl6wAFLD6OFrWZRsACgsBKcwD4obELZp4cAE2WqI76aVnQAJLCBkYmzAA8ACoOmIIA9PFQAMIAFhAAxgDWUPBKUMDpsNAsxY44ILhGALQAVobGptABwlDFcBDCEDjAPrk4BelQbvBGCUk6vQBcw11Q9PnAeGDMraqD8K0qsKJQGUbuKKMDwvCe1aIQYK2Hogi0eKgYewdHYQQF4J3jUBZd0KlgMBrlNEhIUKk8LQAHT7RDxZAZWD0QxKYDxKJfADKSPgYHRm2EeE68QATABOADMADYABwAYkJxLhiG6wGqABYAKyUrkUnmk6yCADaAFEAB5iFgZYDRAA0Ci8al6mkmoUazDsAF0oBBJd13K1hTgIBhYFrBBQAPxQRJQHQ4OoNcLNL7DNRGKAAdxYW3obncusQ+JAlsoUV1+o8rTgSCOGDD1ttS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AQsU48xUCadwGdr7zzvinLkhDXpc1cB4XmFChpAA

`Json` playground link with tests: https://www.typescriptlang.org/play?#code/C4TwDgpgBAUgzgewHZQLxSQVwDbagHygCMEFsIBDFQrAWyIgCcCo5hGBLJAcxfmQDaAXRYBvKALCMEYAFyt2XbkPn8UAXwCwAKB0AzTEgDGwDsijAIbADwAVAHwAKAFaIkqtwEp5ANwQcAEyhRHSgoAHpwqFsrYCgOOHiUYAALaCMEWjAObApTZB0tXW0uS0Y9CiNoAEFg0KgKeToGRgBuQp0dI1y4RIAhOu0wigBCJsx6JnbtIp1QSCgAYTRB4fHJto7i0qYKqqgAEVWJPVJ5Nk4eFQwJlvqBIgoAqRl1luukCB8mLZ0d8sq0AAascKAB+N5TX4lJBlPbQAAaoPkBzyEGmsxhcMBUAAmqCIYc0RjOljdjiAFrIm4bFiGAIQPRcCABEnbWHk-YAdQJ8kcnjQ9gaSBAbK6yDYwpAKywuAaiSootJkSgGSyOSYUAA8gBpOaxRyy7CeaaWNiOCrYOAQE3680ABlt2jNwEcACI3U6XY5hF6DaJ1H7zQJ7UIg67xI0oPaoIHTQbFfKluHHImKIkDinI-JxER5OxMBAADSqnPqdQlgLyAQBksAJhLbpSHDdQjjdtdNYrwSjTZb3aNJYAzGHpjoVWrsuRmKlpAB3OAdw0QOdEyz8lMCT6r1HrzyjpfZjArtcQfmxlNpxLVS8ipN9W-S9NQIGPpMIt-P3GfxIUn9QLkU3pRlmQCFMAFYk2aTVCGAplPjA6YgA
@Gudahtt Gudahtt requested a review from a team as a code owner March 3, 2021 00:41
Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ lgtm!

@Gudahtt Gudahtt merged commit a01da11 into develop Mar 3, 2021
@Gudahtt Gudahtt deleted the fix-JSON-types branch March 3, 2021 14:36
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
The JSON types (`Json` and `IsJsonable`) have been improved:

* The last part of the `Json` union type was redundant, and has been
removed (`Partial<Record<never, never>>`).
* A check has been added to `IsJsonable` to prevent the use of numeric
keys in objects. In testing I've found this doesn't prevent all cases
of this, but it does prevent some.

`IsJsonable` playground link with tests: https://www.typescriptlang.org/play?#code/C4TwDgpgBGBOCWBbex4DdoF4oDsCuANgQLABQUFUAPlAEYD29BEAhjmZdbnorRLB0o0AzsAQ4A5mTKhIUACIQAZvBwoIBEADl6wAFLD6OFrWZRsACgsBKcwD4obELZp4cAE2WqI76aVnQAJLCBkYmzAA8ACoOmIIA9PFQAMIAFhAAxgDWUPBKUMDpsNAsxY44ILhGALQAVobGptABwlDFcBDCEDjAPrk4BelQbvBGCUk6vQBcw11Q9PnAeGDMraqD8K0qsKJQGUbuKKMDwvCe1aIQYK2Hogi0eKgYewdHYQQF4J3jUBZd0KlgMBrlNEhIUKk8LQAHT7RDxZAZWD0QxKYDxKJfADKSPgYHRm2EeE68QATABOADMADYABwAYkJxLhiG6wGqABYAKyUrkUnmk6yCADaAFEAB5iFgZYDRAA0Ci8al6mkmoUazDsAF0oBBJd13K1hTgIBhYFrBBQAPxQRJQHQ4OoNcLNL7DNRGKAAdxYW3obncusQ+JAlsoUV1+o8rTgSCOGDD1ttSQACghkE9oJtHBkMldgC7E+GizM7QB5Qr8L2baAZdLZXL5UqwFih8icKARvW9aO-VRKfhQACq1mFFvbnBtdoAgrAWyBWqVoMJIBl4CwCABuKC1PC7OuZHLN1u65isnqfSBFijBdUuiJDuxjkvJqAVorVuYHht5ea0WqZMARZ2p0BCqOytwutUJqStUYEmlAAACLS4vi1SgeB8S0Gw1QtEWXZRoaf4ATKRZTkkgTAAA5IuAz0P+gHXlAADeTEUHalH8CwvTzGaUBZBAC79MRgF7L6EBsVAwopsJAkgAsnZajMMndgarR3KoUgTh2k6vgASpkeA7OgtYbh8Sj0LAeypPABDuMU7DaTpnC3s6TTRNJWp2JJFClkkEoZAQeCeFUjoaZI-GCcIPmUCaZqbkxAC+L7lpWsCfiUFTzGloXVPRJHAFUdDEjg9BMXF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CIYc0RjOljdjiAFrIm4bFiGAIQPRcCABEnbWHk-YAdQJ8kcnjQ9gaSBAbK6yDYwpAKywuAaiSootJkSgGSyOSYUAA8gBpOaxRyy7CeaaWNiOCrYOAQE3680ABlt2jNwEcACI3U6XY5hF6DaJ1H7zQJ7UIg67xI0oPaoIHTQbFfKluHHImKIkDinI-JxER5OxMBAADSqnPqdQlgLyAQBksAJhLbpSHDdQjjdtdNYrwSjTZb3aNJYAzGHpjoVWrsuRmKlpAB3OAdw0QOdEyz8lMCT6r1HrzyjpfZjArtcQfmxlNpxLVS8ipN9W-S9NQIGPpMIt-P3GfxIUn9QLkU3pRlmQCFMAFYk2aTVCGAplPjA6YgA
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
The JSON types (`Json` and `IsJsonable`) have been improved:

* The last part of the `Json` union type was redundant, and has been
removed (`Partial<Record<never, never>>`).
* A check has been added to `IsJsonable` to prevent the use of numeric
keys in objects. In testing I've found this doesn't prevent all cases
of this, but it does prevent some.

`IsJsonable` playground link with tests: https://www.typescriptlang.org/play?#code/C4TwDgpgBGBOCWBbex4DdoF4oDsCuANgQLABQUFUAPlAEYD29BEAhjmZdbnorRLB0o0AzsAQ4A5mTKhIUACIQAZvBwoIBEADl6wAFLD6OFrWZRsACgsBKcwD4obELZp4cAE2WqI76aVnQAJLCBkYmzAA8ACoOmIIA9PFQAMIAFhAAxgDWUPBKUMDpsNAsxY44ILhGALQAVobGptABwlDFcBDCEDjAPrk4BelQbvBGCUk6vQBcw11Q9PnAeGDMraqD8K0qsKJQGUbuKKMDwvCe1aIQYK2Hogi0eKgYewdHYQQF4J3jUBZd0KlgMBrlNEhIUKk8LQAHT7RDxZAZWD0QxKYDxKJfADKSPgYHRm2EeE68QATABOADMADYABwAYkJxLhiG6wGqABYAKyUrkUnmk6yCADaAFEAB5iFgZYDRAA0Ci8al6mkmoUazDsAF0oBBJd13K1hTgIBhYFrBBQAPxQRJQHQ4OoNcLNL7DNRGKAAdxYW3obncusQ+JAls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NUFZUTlTDBlRE6sxwSrKAQsU48xUCadwGdr7zzvinLkhDXpc1cB4XmFChpAA

`Json` playground link with tests: https://www.typescriptlang.org/play?#code/C4TwDgpgBAUgzgewHZQLxSQVwDbagHygCMEFsIBDFQrAWyIgCcCo5hGBLJAcxfmQDaAXRYBvKALCMEYAFyt2XbkPn8UAXwCwAKB0AzTEgDGwDsijAIbADwAVAHwAKAFaIkqtwEp5ANwQcAEyhRHSgoAHpwqFsrYCgOOHiUYAALaCMEWjAObApTZB0tXW0uS0Y9CiNoAEFg0KgKeToGRgBuQp0dI1y4RIAhOu0wigBCJsx6JnbtIp1QSCgAYTRB4fHJto7i0qYKqqgAEVWJPVJ5Nk4eFQwJlvqBIgoAqRl1luukCB8mLZ0d8sq0AAascKAB+N5TX4lJBlPbQAAaoPkBzyEGmsxhcMBUAAmqCIYc0RjOljdjiAFrIm4bFiGAIQPRcCABEnbWHk-YAdQJ8kcnjQ9gaSBAbK6yDYwpAKywuAaiSootJkSgGSyOSYUAA8gBpOaxRyy7CeaaWNiOCrYOAQE3680ABlt2jNwEcACI3U6XY5hF6DaJ1H7zQJ7UIg67xI0oPaoIHTQbFfKluHHImKIkDinI-JxER5OxMBAADSqnPqdQlgLyAQBksAJhLbpSHDdQjjdtdNYrwSjTZb3aNJYAzGHpjoVWrsuRmKlpAB3OAdw0QOdEyz8lMCT6r1HrzyjpfZjArtcQfmxlNpxLVS8ipN9W-S9NQIGPpMIt-P3GfxIUn9QLkU3pRlmQCFMAFYk2aTVCGAplPjA6YgA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants