mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Parse string unions as StringLiteralUnionTypeAnnotation (#46845)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46845 Previously, the parser was throwing away the values of a string union when storing it in the schema. It would only store the union as ``` { type: 'UnionTypeAnnotation', memberType: 'StringTypeAnnotation' } ``` We now track the string literals through the parser and store them in the schema: ``` { type: 'StringLiteralUnionTypeAnnotation', types: [ { type: 'StringLiteralTypeAnnotation' value: 'light' }, { type: 'StringLiteralTypeAnnotation' value: 'dark' }, ], } ``` We aren't changing the generators, those still just output "string". They could eventually be made smarter. The value of this is that the compat checker can now error when the union changes. Changelog: [Internal] Reviewed By: yungsters Differential Revision: D63917685 fbshipit-source-id: 34a10e1f1910d2935837a3659f66049fd4473134
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1ffef5669c
commit
a669de1dd2
@@ -163,6 +163,8 @@ function serializeArg(
|
||||
return wrap(val => `${val}.asString(rt)`);
|
||||
case 'StringLiteralTypeAnnotation':
|
||||
return wrap(val => `${val}.asString(rt)`);
|
||||
case 'StringLiteralUnionTypeAnnotation':
|
||||
return wrap(val => `${val}.asString(rt)`);
|
||||
case 'BooleanTypeAnnotation':
|
||||
return wrap(val => `${val}.asBool()`);
|
||||
case 'EnumDeclaration':
|
||||
|
||||
Reference in New Issue
Block a user