Skip to content
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

types: optimize ResourceManager overload for type checking #2081

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MrKou47
Copy link
Member

@MrKou47 MrKou47 commented Apr 17, 2024

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

type update

What is the current behavior? (You can also link to an open issue here)

Currently engine.resourceManager.load and the overloads could missing type checking due to the order of overloads. Like:

  // Failed. Indicated that the parameter should be type of `path: string`
  const result = await engine.resourceManager.load<[TextureCube]>([{ type: AssetType.TextureCube, url: '' }]) 
  const result2 = await engine.resourceManager.load<TextureCube[]>(['']) // Failed as before.
  const result3 = await engine.resourceManager.load<TextureCube>('') // Success
  const result4 = await engine.resourceManager.load<TextureCube>({}) // Failed as before

What is the new behavior (if this is a feature change)?

const result = await engine.resourceManager.load<[TextureCube]>([{
  type: AssetType.AnimationClip,
  url: ''
}]) // type check successful

const result2 = await engine.resourceManager.load<TextureCube[]>(['']) // type check successful

const result3 = await engine.resourceManager.load<TextureCube>('') // type check successful

const result4 = await engine.resourceManager.load<TextureCube>({}) // type check failed as expected. Argument of type '{}' is not assignable to parameter of type 'LoadItem'.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No.

@MrKou47 MrKou47 requested review from GuoLei1990 and gz65555 April 17, 2024 20:50
@GuoLei1990
Copy link
Member

GuoLei1990 commented May 9, 2024

其实设计初衷确实是想用 EngineObject 严格规范的!但目前 resourceManager.load 还有个遗留缺陷待解决,AssetType 中有三个枚举 Text、JSON、Buffer 三种类型加载进来不是 EngineObject 并且和其他资产不一样无缓存机制,可以等把这个遗留问题解决后合并此 PR。

稍微了想了下,可以将三种类型统一抽象为 RawAsset(原始或未处理的资产,也继承 EngineObject),API 可参考 fetch 的 response 包含类似 json() text() arrayBuffer() 等方法,使用起来也更方便。 cc: @gz65555

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants