-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround Object.assign issue with type
Fixes #6
- Loading branch information
Showing
9 changed files
with
182 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// @flow | ||
|
||
export function getRequiredTypeStatement( | ||
j: Object, | ||
className: string, | ||
defaultValues: Object | null, | ||
typeProperties: Array<Object>, | ||
) { | ||
if (!defaultValues) { | ||
return null; | ||
} | ||
const defaultPropNames = defaultValues.init.properties.map(p => p.key.name); | ||
const requiredProperties = typeProperties.filter(p => !defaultPropNames.includes(p.key.name)); | ||
return j.typeAlias( | ||
j.identifier(`${className}RequiredArguments`), | ||
null, | ||
j.objectTypeAnnotation(requiredProperties), | ||
); | ||
} | ||
|
||
export function getFullTypeStatement(j: Object, className: string, defaultValues: Object | null) { | ||
if (!defaultValues) { | ||
return null; | ||
} | ||
return j.typeAlias( | ||
j.identifier(`${className}FullType`), | ||
null, | ||
j.intersectionTypeAnnotation([ | ||
j.genericTypeAnnotation(j.identifier(`${className}OptionalArguments`), null), | ||
j.genericTypeAnnotation(j.identifier(`${className}RequiredArguments`), null), | ||
]), | ||
); | ||
} | ||
|
||
export function getFromJSTypeStatement(j: Object, className: string, defaultValues: Object | null) { | ||
if (!defaultValues) { | ||
return null; | ||
} | ||
return j.typeAlias( | ||
j.identifier(`${className}FromJSType`), | ||
null, | ||
j.intersectionTypeAnnotation([ | ||
j.genericTypeAnnotation( | ||
j.identifier('$Shape'), | ||
j.typeParameterInstantiation([ | ||
j.genericTypeAnnotation(j.identifier(`${className}FullType`), null), | ||
]), | ||
), | ||
j.genericTypeAnnotation(j.identifier(`${className}RequiredArguments`), null), | ||
]), | ||
); | ||
} | ||
|
||
export function getOptionalTypeStatement( | ||
j: Object, | ||
className: string, | ||
defaultValues: Object | null, | ||
) { | ||
if (!defaultValues) { | ||
return null; | ||
} | ||
return j.typeAlias( | ||
j.identifier(`${className}OptionalArguments`), | ||
null, | ||
j.typeofTypeAnnotation(j.genericTypeAnnotation(j.identifier(defaultValues.id.name), null)), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters