Code Monkey home page Code Monkey logo

Comments (5)

jonaskello avatar jonaskello commented on June 2, 2024

It would probably make more sense to merge readonly-interface and readonly-indexer since both are based on the readonly keyword. But readonly-array is based on the ReadonlyArray<T> type so it should probably be its own rule.

from tslint-immutable.

jonaskello avatar jonaskello commented on June 2, 2024

So we could have a readonly-keyword rule that would enforce the use of the readonly keyword in all places it is allowed. So the first thing is to find all places wherereadonly is allowed. However I cannot find an updated version of the typescript language specification that includes this. So I'll try to collect them here:

Interface members (including indexers):

interface Foo {
  readonly bar: string,
  readonly [key: string]: string,
}

Object type alias members (including indexers):

type Foo = {
  readonly bar: string,
  readonly [key: string]: string,
}

Object type literals (including indexers):

let foo: { readonly bar: string, readonly [key: string]: string}; 

Class members (we don't want to support this?)

class Circle {
  readonly radius: number;
}

from tslint-immutable.

jonaskello avatar jonaskello commented on June 2, 2024

It seems that in all of the above cases, the type of nodes allowing readonly are the same. They are either PropertySignature or IndexSignature.

So maybe a check for readonly on all PropertySignature and IndexSignature nodes will work. And perhaps it can be done regardless of where those nodes are found.

from tslint-immutable.

jonaskello avatar jonaskello commented on June 2, 2024

This is the only official mention of where readonly is allowed I can find. It seems to support the theory that readonly is allowed on PropertySignature and IndexSignature nodes:

A property or index signature can now be declared with the readonly modifier

from tslint-immutable.

jonaskello avatar jonaskello commented on June 2, 2024

Continued in #31.

from tslint-immutable.

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.