美化打字稿编译 - 省略类型编译成为 Pick

时间:2021-02-01 03:39:39

标签: typescript compilation

我目前在 ts 中制作了一些小库,并且也在 ts 中编译了它。 但就我而言,它使尺寸比我大,但除外。为什么?我认为是因为编译器没有简化代码

我有这样的代码

type TProps = {
    props?: Omit<RNViewProps, 'style'>
}

export const myFn = (iProps: TProps) => {
    const { props = {} } = iProps
    return {
        MyView: ({ onLayout, ...rest }: typeof props) => {
            return null
        }
    }
}

这里是我的 tsconfig

{
    "$schema":"https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/tsconfig.json",
    "compilerOptions": {
        "target": "ES2020",
        "module": "ES2020",
        "strict": true,
        "outDir": "./lib",
        "jsx": "react-native",
        "allowUmdGlobalAccess": true,
        "downlevelIteration": true,
        "pretty": true,
        "sourceMap": true,
        "skipLibCheck": true,
        "esModuleInterop": false,
        "declaration": true,
        "moduleResolution": "Node",
        "allowSyntheticDefaultImports": true
    },
    "include": [
        "src"
    ],
    "exclude": [
        "node_modules",
        "**/__tests__/*"
    ]
}

但是为什么在我运行 tsc --project ./tsconfig.json 之后,它变成了

declare type TProps = {
    props?: Omit<RNViewProps, 'style'>;
};
export declare const myFn: (iProps: TProps) => {
    MyView: ({ onLayout, ...rest }: Pick<RNViewProps, "onLayout" | "testID" | "nativeID" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "hitSlop" | "pointerEvents" | "removeClippedSubviews" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture">) => null;
};

结果,很多重写的代码

1

0 个答案:

没有答案