TypeScript自动“作为常量”我的类型,导致错误
请参阅以下类型脚本代码:TypeScript自动“作为常量”我的类型,导致错误,typescript,Typescript,请参阅以下类型脚本代码: type Interpolation = null | undefined | boolean | number | string; type DefaultTheme = { color: { primary: { active: string; default: string; hover: string; disabled: string;
type Interpolation = null | undefined | boolean | number | string;
type DefaultTheme = {
color: {
primary: {
active: string;
default: string;
hover: string;
disabled: string;
background: string;
};
secondary: {
active: string;
default: string;
hover: string;
disabled: string;
background: string;
};
};
};
type Classes<K extends string> = {
[className in K]: string;
};
type Theme = DefaultTheme & {
[key: string]: any;
};
type DynamicStyle<K extends string> = (
theme: Theme,
deps: any[],
classes: Classes<K>,
) => Interpolation;
type Style<K extends string> = string | DynamicStyle<K>;
type Styles<K extends string> = ReadonlyArray<readonly [K, Style<K>]>;
function makeStyles<K extends string>(styles: Styles<K>) {
return styles;
}
makeStyles([
[
'tag',
(theme, [a, b, c]) => {
return '';
},
],
['label', ''],
]);
我知道这个问题,因为这一行
ReadonlyArray
这似乎缩小了我的类型
{
"include": ["src", "types", "test"],
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
}
}