Transform mixed to unknown in xplat/js (#54954)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54954

We are transforming the following utility types to be more consistent with typescript and better AI integration:

* `$NonMaybeType` -> `NonNullable`
* `$ReadOnly` -> `Readonly`
* `$ReadOnlyArray` -> `ReadonlyArray`
* `$ReadOnlyMap` -> `ReadonlyMap`
* `$ReadOnlySet` -> `ReadonlySet`
* `$Keys` -> `keyof`
* `$Values` -> `Values`
* `mixed` -> `unknown`

See details in https://fb.workplace.com/groups/flowlang/permalink/1837907750148213/.
drop-conflicts

Reviewed By: SamChou19815

Differential Revision: D89581744

fbshipit-source-id: 58a6c246629bbe4fb5c0af447dc002c48e10c342
This commit is contained in:
Marco Wang authored and meta-codesync[bot] committed 2025-12-22 12:25:44 -08:00
1 parent 2624e2f52e
commit 894a1f16ef
131 files changed
+409 -409

No files matched your search

@@ -30,14 +30,14 @@ const osTempDir = require('temp-dir');
const {globSync} = require('tinyglobby');
const {styleText} = require('util');
const inputFilesPostTransforms: $ReadOnlyArray<PluginObj<mixed>> = [
const inputFilesPostTransforms: $ReadOnlyArray<PluginObj<unknown>> = [
require('./transforms/typescript/renameDefaultExportedIdentifiers'),
require('./transforms/typescript/stripUnstableApis'),
];
const postTransforms = (
options: BuildApiSnapshotOptions,
): $ReadOnlyArray<PluginObj<mixed>> => [
): $ReadOnlyArray<PluginObj<unknown>> => [
require('./transforms/typescript/simplifyTypes'),
require('./transforms/typescript/sortProperties'),
require('./transforms/typescript/sortUnions'),
@@ -19,7 +19,7 @@ import * as t from '@babel/types';
* - Sorts declarations alphabetically.
* - Moves all exports into a single block at the end of the file.
*/
const visitor: PluginObj<mixed> = {
const visitor: PluginObj<unknown> = {
visitor: {
Program(path) {
const exportedIdentifiers: Set<string> = new Set();
@@ -12,7 +12,7 @@ import type {PluginObj} from '@babel/core';
import * as t from '@babel/types';
const visitor: PluginObj<mixed> = {
const visitor: PluginObj<unknown> = {
visitor: {
TSPropertySignature(path) {
if (path.node.optional !== true) {
@@ -22,7 +22,7 @@ import * as t from '@babel/types';
* the symbol. Finally, it replaces occurences of the local symbol by suffixing
* it with `_default`.
*/
const visitor: PluginObj<mixed> = {
const visitor: PluginObj<unknown> = {
visitor: {
Program(nodePath) {
let localSymbol: ?string = null;
@@ -10,7 +10,7 @@
import type {PluginObj} from '@babel/core';
function createDefaultExportNameReplacer(filePath: string): PluginObj<mixed> {
function createDefaultExportNameReplacer(filePath: string): PluginObj<unknown> {
return {
visitor: {
Identifier(node) {
@@ -65,4 +65,4 @@ const mergeObjects: PluginObj<BaseVisitorState> = {
};
// Visitor state is only used internally, so we can safely cast to PluginObj<mixed>.
module.exports = mergeObjects as $FlowFixMe as PluginObj<mixed>;
module.exports = mergeObjects as $FlowFixMe as PluginObj<unknown>;
@@ -253,4 +253,4 @@ const inlineTypes: PluginObj<InlineVisitorState> = {
};
// Visitor state is only used internally, so we can safely cast to PluginObj<mixed>.
module.exports = inlineTypes as $FlowFixMe as PluginObj<mixed>;
module.exports = inlineTypes as $FlowFixMe as PluginObj<unknown>;
@@ -78,7 +78,7 @@ function sortMembers<T>(members: T[]): T[] {
.concat(enumMembers);
}
const visitor: PluginObj<mixed> = {
const visitor: PluginObj<unknown> = {
visitor: {
TSInterfaceBody(path) {
path.node.body = sortMembers(path.node.body);
@@ -13,7 +13,7 @@ import type {PluginObj} from '@babel/core';
import generate from '@babel/generator';
import * as t from '@babel/types';
const visitor: PluginObj<mixed> = {
const visitor: PluginObj<unknown> = {
visitor: {
TSUnionType(path) {
path.node.types.sort((a, b) => {
@@ -18,7 +18,7 @@ function isUnstableSymbol(name: ?string): boolean {
);
}
const stripUnstableProperties: PluginObj<mixed> = {
const stripUnstableProperties: PluginObj<unknown> = {
visitor: {
TSPropertySignature(path) {
if (isUnstableSymbol(path.node.key.name)) {
@@ -31,7 +31,7 @@ const debug = require('debug')('build-types:transforms:versionExportedApis');
*/
function createVersionExportedApis(
outputDebugAnnotations: boolean = false,
): PluginObj<mixed> {
): PluginObj<unknown> {
return {
visitor: {
Program(path) {
@@ -28,7 +28,7 @@ const preTransforms: Array<PreTransformFn> = [
require('./transforms/flow/reattachDocComments'),
require('./transforms/flow/ensureNoUnprefixedProps'),
];
const postTransforms = (filePath: string): Array<PluginObj<mixed>> => [
const postTransforms = (filePath: string): Array<PluginObj<unknown>> => [
require('./transforms/typescript/replaceDefaultExportName')(filePath),
];
const prettierOptions = {parser: 'babel'};
@@ -17,7 +17,7 @@ import * as babel from '@babel/core';
*/
async function applyBabelTransformsSeq(
source: string,
transforms: $ReadOnlyArray<PluginObj<mixed>>,
transforms: $ReadOnlyArray<PluginObj<unknown>>,
): Promise<string> {
const parsed = await babel.parseAsync(source, {
plugins: ['@babel/plugin-syntax-typescript'],