-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A better tsconfig.json #16542
A better tsconfig.json #16542
Conversation
一个更合理的 tsconfig配置
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -992,9 +992,9 @@
protected _pixelsToUnit: number;
protected _pivot: math.Vec2;
protected _meshType: __private._cocos_2d_assets_sprite_frame__MeshType;
protected _extrude: number;
- protected _customOutLine: never[];
+ protected _customOutLine: any[];
protected _mesh: Mesh | null;
protected _minPos: math.Vec3;
protected _maxPos: math.Vec3;
constructor();
@@ -7306,9 +7306,9 @@
* 动画曲线。
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
export class AnimCurve {
- static Linear: null;
+ static Linear: any;
static Bezier(controlPoints: number[]): BezierControlPoints;
types?: Array<(AnimationClip._legacy.LegacyEasingMethod | null)>;
type?: AnimationClip._legacy.LegacyEasingMethod | null;
constructor(propertyCurveData: Omit<AnimationClip._legacy.LegacyClipCurveData, "keys">, duration: number);
@@ -17642,18 +17642,18 @@
raySphere: (ray: Ray, sphere: Sphere) => number;
rayAABB: (ray: Ray, aabb: AABB) => number;
rayOBB: (ray: Ray, obb: OBB) => number;
rayPlane: (ray: Ray, plane: Plane) => number;
- rayTriangle: (ray: Ray, triangle: Triangle, doubleSided?: boolean | undefined) => number;
+ rayTriangle: (ray: Ray, triangle: Triangle, doubleSided?: boolean) => number;
rayCapsule: (ray: Ray, capsule: Capsule) => number;
- raySubMesh: (ray: Ray, submesh: RenderingSubMesh, options?: IRaySubMeshOptions | undefined) => number;
- rayMesh: (ray: Ray, mesh: Mesh, options?: IRayMeshOptions | undefined) => number;
- rayModel: (r: Ray, model: renderer.scene.Model, options?: IRayMeshOptions | undefined) => number;
+ raySubMesh: (ray: Ray, submesh: RenderingSubMesh, options?: IRaySubMeshOptions) => number;
+ rayMesh: (ray: Ray, mesh: Mesh, options?: IRayMeshOptions) => number;
+ rayModel: (r: Ray, model: renderer.scene.Model, options?: IRayModelOptions) => number;
lineSphere: typeof __private._cocos_core_geometry_intersect__lineSphere;
lineAABB: typeof __private._cocos_core_geometry_intersect__lineAABB;
lineOBB: typeof __private._cocos_core_geometry_intersect__lineOBB;
linePlane: (line: Line, plane: Plane) => number;
- lineTriangle: (line: Line, triangle: Triangle, outPt?: math.Vec3 | undefined) => number;
+ lineTriangle: (line: Line, triangle: Triangle, outPt?: math.Vec3) => number;
sphereWithSphere: (sphere0: Sphere, sphere1: Sphere) => boolean;
sphereAABB: (sphere: Sphere, aabb: AABB) => boolean;
sphereOBB: (sphere: Sphere, obb: OBB) => boolean;
spherePlane: (sphere: Sphere, plane: Plane) => number;
@@ -17680,9 +17680,9 @@
* @param g2 @en The second geometry. @zh 第二个几何体。
* @param outPt @en A 3d point to store the intersection point result, only part of the geometries support this.
* @zh 可选,用于保存相交点的输出对象。(注:仅部分形状的检测带有这个返回值)
*/
- resolve(g1: any, g2: any, outPt?: null): number;
+ resolve(g1: any, g2: any, outPt?: any): number;
};
/**
* @en
* Basic Geometry: Line.
@@ -19842,12 +19842,12 @@
extend: typeof extend;
getSuper: typeof getSuper;
isChildClassOf: typeof isChildClassOf;
clear: typeof clear;
- value: (object: Record<string | number, any>, propertyName: string, value_: any, writable?: boolean | undefined, enumerable?: boolean | undefined) => void;
- getset: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, setter?: boolean | __private._types_globals__Setter | undefined, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
- get: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
- set: (object: Record<string | number, any>, propertyName: string, setter: __private._types_globals__Setter, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
+ value: (object: Record<string | number, any>, propertyName: string, value_: any, writable?: boolean, enumerable?: boolean) => void;
+ getset: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, setter?: boolean | __private._types_globals__Setter, enumerable?: boolean, configurable?: boolean) => void;
+ get: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, enumerable?: boolean, configurable?: boolean) => void;
+ set: (object: Record<string | number, any>, propertyName: string, setter: __private._types_globals__Setter, enumerable?: boolean, configurable?: boolean) => void;
unregisterClass: typeof unregisterClass;
getClassName: typeof getClassName;
setClassName: typeof setClassName;
setClassAlias: typeof setClassAlias;
@@ -20211,9 +20211,9 @@
* @zh 要添加的属性值,或者取代现有属性的新值。
* @param writable @en If the property is writable. @zh 属性是否可写。
* @param enumerable @en If the property is enumerable. @zh 属性是否可枚举。
*/
- export const value: (object: Record<string | number, any>, propertyName: string, value_: any, writable?: boolean | undefined, enumerable?: boolean | undefined) => void;
+ export const value: (object: Record<string | number, any>, propertyName: string, value_: any, writable?: boolean, enumerable?: boolean) => void;
/**
* @en A helper function to add or modify `get`, `set`, `enumerable` or `configurable` of a property.
* @zh 添加或修改属性的 `get`, `set`, `enumerable` 或者 `configurable`。
* @param object @en The object to add or modify attributes. @zh 要添加或者修改属性的对象。
@@ -20222,9 +20222,9 @@
* @param setter @en The setter of a property. @zh 属性的设置函数。
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
- export const getset: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, setter?: boolean | __private._types_globals__Setter | undefined, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
+ export const getset: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, setter?: __private._types_globals__Setter | boolean, enumerable?: boolean, configurable?: boolean) => void;
/**
* @en A helper function to add or modify `get`, `enumerable` or `configurable` of a property.
* @zh 添加或修改属性的 `get`, `enumerable` 或者 `configurable`。
* @param object @en The object to add or modify attributes. @zh 要添加或者修改属性的对象。
@@ -20232,9 +20232,9 @@
* @param getter @en The getter of a property. @zh 属性的获取函数。
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
- export const get: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
+ export const get: (object: Record<string | number, any>, propertyName: string, getter: __private._types_globals__Getter, enumerable?: boolean, configurable?: boolean) => void;
/**
* @en A helper function to add or modify `get`, `enumerable` or `configurable` of a property.
* @zh 添加或修改属性的 `get`, `enumerable` 或者 `configurable`。
* @param object @en The object to add or modify attributes. @zh 要添加或者修改属性的对象。
@@ -20242,9 +20242,9 @@
* @param setter @en The setter of a property. @zh 属性的设置函数。
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
- export const set: (object: Record<string | number, any>, propertyName: string, setter: __private._types_globals__Setter, enumerable?: boolean | undefined, configurable?: boolean | undefined) => void;
+ export const set: (object: Record<string | number, any>, propertyName: string, setter: __private._types_globals__Setter, enumerable?: boolean, configurable?: boolean) => void;
/**
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
export const _idToClass: Record<string, __private._types_globals__Constructor>;
@@ -23840,9 +23840,9 @@
export class PipelineStateManager {
static getOrCreatePipelineState(device: gfx.Device, pass: renderer.Pass, shader: gfx.Shader, renderPass: gfx.RenderPass, ia: gfx.InputAssembler): gfx.PipelineState;
}
export class PipelineEventProcessor extends EventTarget {
- eventTargetOn: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any, once?: boolean | undefined) => TFunction;
+ eventTargetOn: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any, once?: boolean) => TFunction;
eventTargetOnce: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any) => TFunction;
on(type: PipelineEventType, callback: any, target?: any, once?: boolean): typeof callback;
once(type: PipelineEventType, callback: any, target?: any): typeof callback;
}
@@ -25005,9 +25005,9 @@
*
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
_globals: SceneGlobals;
- dependAssets: null;
+ dependAssets: any;
protected _renderScene: renderer.RenderScene | null;
protected _inited: boolean;
protected _prefabSyncedInLiveReload: boolean;
protected _updateScene(): void;
@@ -25293,9 +25293,9 @@
*
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
get _isOnLoadCalled(): number;
- static system: null;
+ static system: any;
/**
* @en The node this component is attached to. A component is always attached to a node.
* @zh 该组件被附加到的节点。组件总会附加到一个节点。
* @example
@@ -27142,9 +27142,9 @@
static safeFindClass(id: string): __private._types_globals__Constructor<unknown> | undefined;
/**
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
- _$erialized: null;
+ _$erialized: any;
constructor();
onLoad(): void;
}
/**
@@ -27810,9 +27810,9 @@
* @en The renderer backend of the game.
* @zh 游戏的渲染器类型。
*/
renderType: number;
- eventTargetOn: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any, once?: boolean | undefined) => TFunction;
+ eventTargetOn: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any, once?: boolean) => TFunction;
eventTargetOnce: <TFunction extends (...any: any[]) => void>(type: string | number, callback: TFunction, thisArg?: any) => TFunction;
/**
* @en
* The current game configuration,
@@ -29657,9 +29657,9 @@
loadPipe: typeof __private._cocos_asset_asset_manager_load__default;
/**
* @internal
*/
- references: AssetManager.Cache<any[]> | null;
+ references: AssetManager.Cache<any[]>;
/**
* @en
* A global singleton instance of [[AssetManager]], which you can access directly through [[assetManager]].
*
@@ -49516,16 +49516,16 @@
export function cylinder(radiusTop?: number, radiusBottom?: number, height?: number, opts?: __private._types_globals__RecursivePartial<__private._cocos_primitive_cylinder__ICylinderOptions>): primitives.IGeometry;
export const VEC3_0: math.Vec3;
export const TriggerEventObject: {
type: TriggerEventType;
- selfCollider: Collider | null;
- otherCollider: Collider | null;
+ selfCollider: Collider;
+ otherCollider: Collider;
impl: any;
};
export const CharacterTriggerEventObject: {
type: CharacterTriggerEventType;
- collider: Collider | null;
- characterController: CharacterController | null;
+ collider: Collider;
+ characterController: CharacterController;
impl: any;
};
export const CollisionEventObject: {
type: CollisionEventType;
@@ -56927,15 +56927,15 @@
animationState: {
previewing: boolean;
time: number;
animatedSinceLastFrame: boolean;
- } | null;
+ };
init(): void;
add(widget: Widget): void;
remove(widget: Widget): void;
onResized(): void;
refreshWidgetOnResized(node: Node): void;
- updateOffsetsToStayPut(widget: Widget, e?: __private._cocos_ui_widget__AlignFlags | undefined): void;
+ updateOffsetsToStayPut(widget: Widget, e?: __private._cocos_ui_widget__AlignFlags): void;
updateAlignment: typeof __private._cocos_ui_widget_manager__updateAlignment;
AlignMode: typeof __private._cocos_ui_widget__AlignMode;
AlignFlags: typeof __private._cocos_ui_widget__AlignFlags;
};
@@ -65916,9 +65916,9 @@
* @en Space used to calculate limit velocity.
* @zh 计算速度下限时采用的坐标系 [[Space]]。
*/
space: number;
- drag: null;
+ drag: any;
multiplyDragByParticleSize: boolean;
multiplyDragByParticleVelocity: boolean;
name: string;
constructor();
|
" npm test / npm_test (pull_request) " 中报的错和我提交的这个 配置文件关系不大, 是代码确实就有错. |
为了更好的兼容性, 改回 "module": "commonjs",
"strict": true, | ||
"noImplicitAny": false, | ||
"strictNullChecks": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.typescriptlang.org/tsconfig#strictNullChecks
Why set strictNullChecks
to false ? I think strict null check
is needed.
"strict": true, | ||
"noImplicitAny": false, | ||
"strictNullChecks": false, | ||
"strictPropertyInitialization": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.typescriptlang.org/tsconfig#strictPropertyInitialization
Why set strictPropertyInitialization
to false ?
"strict": true, | ||
"noImplicitAny": false, | ||
"strictNullChecks": false, | ||
"strictPropertyInitialization": false, | ||
"strictFunctionTypes": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is true
, but, yes, it's better to set it to true explicitly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is
true
, but, yes, it's better to set it to true explicitly here.
// 如果 "strictPropertyInitialization" 为 true , 会面临下面的问题:
class KlassFoo {
}
class KlassA {
// 必须实例化一个 KlassFoo, 显然是不科学的. foo 有可能需要延迟创建.
foo: KlassFoo = new KlassFoo();
}
class KlassB {
// 需要被迫增加一个 undefined , 破坏了 foo 的原本的意义,
// 且代码变得冗繁, 到最后项目里会有非常多的 `| undefined`
foo: KlassFoo | undefined;
}
class KlassC {
// 被迫加一个 ! , 来欺骗编译器, 这么做是非常危险的
foo: KlassFoo = null!
}
/*
按照 strictPropertyInitialization 的设计, 其实只有 KlassA 是正道.
后面的两种方案都是为了屏蔽编译器报错 而采取的 "欺骗手段"
但是在实际项目里, KlassA 的做法显然也是不可取的.
成员变量(属性)的类型声明, 本身就是为了声明类型, 而不是创建这个成员变量.
ts里 strictPropertyInitialization=true 的设计, 强迫把声明过程 和 实例化过程混在一起,
是一个 并不好的设计.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strictNullChecks 为什么要设置成 false 是一个更复杂的话题.
有空再说吧
一个更合理的 tsconfig配置.
建议与 #16118 配合使用
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: