Skip to content

导出 SpriteType 类型#38

Open
finscn wants to merge 2 commits intococos:v4.0.0from
finscn:patch-2
Open

导出 SpriteType 类型#38
finscn wants to merge 2 commits intococos:v4.0.0from
finscn:patch-2

Conversation

@finscn
Copy link

@finscn finscn commented Jan 7, 2026

在项目中有时需要判断 sprite对象的 type .

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

在项目中有时需要判断 sprite对象的 type .
@star-e star-e self-requested a review January 12, 2026 09:18
@star-e star-e self-assigned this Jan 12, 2026
@star-e star-e added the investigation Investigate the impact on the code base label Jan 12, 2026
@gaojie111119
Copy link

Sprite.Type 在大部分时候能用吧…… 我看之前的设计思路像是把这些类型放在静态属性上

@finscn
Copy link
Author

finscn commented Jan 18, 2026

Sprite.Type 在大部分时候能用吧…… 我看之前的设计思路像是把这些类型放在静态属性上

是的. 你说的对 . Sprite.Type 是值, 但是要用到类型时, 总是要 typeof Sprite.Type 很烦.

我这里确实说写了. 应该是

export type { SpriteType } from './sprite';

类似的还有

export type { PixelFormat, TextureFilter, WrapMode } from './asset-enum';

他们对应的值是 cc.RenderTexture.PixelFormat/Filter/WrapMode.

不过这个事情 倒是也可以让 开发者自己在项目里 类给类型设置别名 来解决.

export type SpriteType = typeof cc.Sprite.Type;
export type PixelFormat = typeof cc.RenderTexture.PixelFormat;
export type TextureFilter = typeof cc.RenderTexture.Filter;
export type WrapMode = typeof cc.RenderTexture.WrapMode;

所以这个 PR 倒也不是必须.


不过 有些重要的 类或者值 确实没有导出, 导致开发者难以在项目中进行使用(继承 聚合 实例化 类型声明等).
比如

export type { IBatcher } from './i-batcher';
export type { Batcher2D } from './batcher-2d';

export { StaticVBAccessor, StaticVBChunk } from './static-vb-accessor';
export { RenderDrawInfo, RenderDrawInfoType } from './render-draw-info';
export { RenderEntity, RenderEntityType, RenderEntityFillColorType } from './render-entity';
export { Stage, StencilManager } from './stencil-manager';

还有

export { TextureBase } from './texture-base';

@gaojie111119
Copy link

export type { Batcher2D } from './batcher-2d';

这个最可怕 在deprecated.ts里重命名为 UI 导出了……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

investigation Investigate the impact on the code base

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants