Giter VIP home page Giter VIP logo

Comments (7)

MartinJohns avatar MartinJohns commented on May 23, 2024 1
  • I was unable to test this on prior versions because I'm using TS Playground

Especially on the playground it's easy to test this on prior versions because the playground has a version selector on the top left.

from typescript.

whzx5byb avatar whzx5byb commented on May 23, 2024 1

Strangely, this doesn't work, either.

This works in 5.5 beta. For more information, see https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#control-flow-narrowing-for-constant-indexed-accesses

from typescript.

delosford avatar delosford commented on May 23, 2024
  • I was unable to test this on prior versions because I'm using TS Playground

Especially on the playground it's easy to test this on prior versions because the playground has a version selector on the top left.

I was unaware of that. Thanks for letting me know. I tested it back a few versions and they all produce the same errors.

from typescript.

ahejlsberg avatar ahejlsberg commented on May 23, 2024

This is working as intended. A readonly reference doesn't guarantee that the underlying object isn't mutated. I just guarantees that it isn't mutated through that reference. You need to store the value of arrayAccessors[0] in a const local to get the desired behavior.

from typescript.

delosford avatar delosford commented on May 23, 2024
function itsaFunction(arrayAccessors: readonly number[])
{
	let someArray: Array<Array<Array<number | null> | null> | null> = new Array<Array<Array<number | null> | null> | null>();

	const arrAcc1 = arrayAccessors[0];
	const arrAcc2 = arrayAccessors[1];

	if (someArray[arrAcc1] !== null && someArray[arrAcc1][arrAcc2] != null)
 		console.log(arrayAccessors);
}

Strangely, this doesn't work, either. Gives the same error.

from typescript.

delosford avatar delosford commented on May 23, 2024

Strangely, this doesn't work, either.

This works in 5.5 beta. For more information, see https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#control-flow-narrowing-for-constant-indexed-accesses

Thanks for the info. Good to know this is at least being addressed.

from typescript.

typescript-bot avatar typescript-bot commented on May 23, 2024

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.