TensorArray throws AttributeError in gradient computation 
Hi @trickiwoo,

As TensorArray is a wrapper class for dynamic sized,, per-time-step, Tensor arrays. Also from documentation this class is meant to be used with dynamic iteration primitives such as `while_loop` and `map_fn`. 

It supports gradient `back-propagation` via special "flow" control flow dependencies. Please also refer to [tf.raw_ops](https://www.tensorflow.org/api_docs/python/tf/raw_ops) which confirms it supports gradient.

For your case mentioned since they are not using any dynamic iteration primitives, you can use `tf.stack()` to collect all elements at once and then apply gradients or use `tf.read()` iteratively to collect elements one by one and apply gradients.
However the correct way to use TensorArray is by using with dynamic iteration primitives such as `while_loop` and `map_fn`.

I just added a simple [gist](https://colab.research.google.com/gist/SuryanarayanaY/c84d303dd7d569bcfe4c73bf79a8a2be/60048.ipynb#scrollTo=NfqXvYrilJqE) here for your reference. Please let us know if it helps.

Thank you! Hi @SuryanarayanaY , thanks for your detailed inputs! 

I've tried your example with the `for` loop and it works well with the gradient computation:

```
v = tf.Variable(1)
@tf.function
def f(x):
  ta = tf.TensorArray(tf.int32, size=0, dynamic_size=True)
  for i in tf.range(x):
    v.assign_add(i)
    ta = ta.write(i, v)
  return ta
f(5)
```
And made a few modifications as follows. It turns out that without dynamic iteration primitives, `tf.read()`, or `tf.stack()`, it doesn't throw any error, contrasting the case I reported before. The usage of TensorArray, and whether it supports back propagation seems vague. I think it would be great if there could have a consistently defined behavior or produce a better error message.
```
import os
import tensorflow as tf
import numpy as np

v = tf.Variable(1)
@tf.function
def f(x):
  ta = tf.TensorArray(tf.int32, size=4, dynamic_size=True)
  ta = ta.write(0, v)
  return ta


with tf.GradientTape() as tape:
    tape.watch(v)
    t = f(5)
gradient = tape.jacobian(t, v)
``` Hi @trickiwoo ,

Could I know what error message you want to display?(I assuming you want to display the error regarding the usage of TensorArray w.r.t Gradients). Due to performance reasons all the checks are not getting validated. If you want to propose some changes to documentation or want to accommodate user error or want to add some more example codes please feel free to propose a PR and Team may happily review it. 

Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60048">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60048">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.11

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
The [documentation](https://www.tensorflow.org/api_docs/python/tf/TensorArray) claims that TensorArray "supports gradient back-propagation via special "flow" control flow dependencies". However, it seems that `TensorArray` is an [unsupported type](https://github.com/tensorflow/tensorflow/blob/d5b57ca93e506df258271ea00fc29cf98383a374/tensorflow/python/ops/gradient_checker_v2.py#L261) for gradient computation at the moment. It would be great if there is clarification, in documentation or better error message.
```


### Standalone code to reproduce the issue

```shell
import tensorflow as tf

elems = tf.ones(shape=[2])

def init_tensor_array(elems):

    ta = tf.TensorArray(dtype=tf.float32, size=4, dynamic_size=True)
    ta = ta.write(0, elems)
    return ta

ta = init_tensor_array(elems)
with tf.GradientTape() as tape:
    tape.watch(elems)
    t = init_tensor_array(elems)

gradient = tape.jacobian(t, elems)
```


### Relevant log output

```shell
AttributeError: 'TensorArray' object has no attribute 'shape'
```
</details>