0

tickList is (or should be) an Array of type number

fpsObject = {
  maxSamples: 100,
  tickIndex: 0,
  tickSum: 0,
  tickList: []
}

Can I enforce this type without creating an interface? Or must I create an interface to do this? I would rather avoid creating an interface if at all possible. I've got too many interface files already!

2 Answers 2

2

You can use as to type it:

const fpsObject = {
  maxSamples: 100,
  tickIndex: 0,
  tickSum: 0,
  tickList: [] as number[]
}

Typescript Playground

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, looks a tad messy but better than a kick up the pants :D
1

You can use this way also:

const fpsObject = {
  maxSamples: 100,
  tickIndex: 0,
  tickSum: 0,
  tickList: Array<number>()
}
console.log(fpsObject)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.